Skip to main content
On Chat Completions, pass response_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:
Guaranteed parseable, not guaranteed shaped — validate before trusting field names.

On the Messages dialect

The Anthropic dialect expresses shapes through tools: define a tool whose input_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: true and additionalProperties: 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_tokens generously — hidden reasoning counts against it before the JSON is emitted.
  • Always validate before acting — a 400 on an impossible constraint or a truncated length finish is recoverable if you check for it (Errors).