Designing a JSON Schema
Shape the output to exactly what you need.
Why Schema-Shaped Output
When you need Claude's answer in a precise structure, don't parse free text and hope. Pair tool_use with a JSON Schema: Claude fills a tool's input_schema and the API guarantees valid JSON with your required fields present.
This eliminates two whole classes of failure: syntax errors (missing commas, unescaped quotes) and missing fields. The schema IS the contract — design it well and downstream code never has to defend against malformed shapes.
The Tool Is the Schema
A structured-output "tool" doesn't have to call anything. It's just a named container whose input_schema describes the shape you want back. You define it, then read what Claude put in the tool call.
Give the tool a clear name and description — these still drive selection — but the real work is in the schema's properties and required list.
extract_invoice = {
"name": "extract_invoice",
"description": "Record the structured fields parsed from an invoice document.",
"input_schema": {
"type": "object",
"properties": {
"invoice_number": {"type": "string"},
"total": {"type": "number"},
},
"required": ["invoice_number", "total"],
},
}