JSON schema (recommended)
On Chat Completions, passresponse_format.type: "json_schema" with your schema. The response content is a single
JSON document conforming to it — parse and go.
Response content
JSON mode
When any valid JSON is enough and the exact shape can flex, use{ "type": "json_object" } and describe the fields you want in the prompt:
On the Messages dialect
The Anthropic dialect expresses shapes through tools: define a tool whoseinput_schema
is your output schema and force it with tool_choice — the arguments of the resulting
tool_use block are your structured output.
Force the 'record_person' tool
Practical notes
- Set
strict: trueandadditionalProperties: false— schemas that forbid extras fail loud instead of drifting quietly. - Keep schemas shallow. Deeply nested optional trees invite empty objects; several flat calls beat one cathedral schema.
- Reasoning models produce excellent structured output but budget
max_tokensgenerously — hidden reasoning counts against it before the JSON is emitted. - Always validate before acting — a
400on an impossible constraint or a truncatedlengthfinish is recoverable if you check for it (Errors).