Structured output
How do you make a model match an exact JSON shape?
JSON mode guarantees parseable JSON but not its shape. Passing a JSON Schema with strict mode pins the exact fields, types, and allowed values, so the output matches what your code expects.
There are two levels of help, and they are easy to confuse.
JSON mode asks the model to return only valid JSON. The text will parse, but nothing checks that it has the fields you wanted. OpenAI calls this json_object and notes that JSON mode “only ensures valid JSON output,” in contrast to the stronger option below.[1]
Schema-enforced output goes further. You hand the model a JSON Schema, a small specification listing the field names, their types, and any fixed set of allowed values. You then turn on strict mode. OpenAI’s version is response_format: { "type": "json_schema", "json_schema": { "strict": true, ... } }, and the guide recommends “always using Structured Outputs instead of JSON mode when possible.”[1] Anthropic offers the same idea: structured outputs “constrain Claude’s responses to follow a specific schema,” giving output that is “Always valid,” “Type safe,” and “Reliable.”[2]
There is a second place this shows up: tool calls. When a model calls a function, its arguments are themselves structured data, so the same schema enforcement applies there. OpenAI separates the two uses, noting that response_format is “more suitable when you want to indicate a structured schema for use when the model responds to the user, rather than when the model calls a tool.”[1] Anthropic exposes this as strict: true on a tool to “guarantee schema validation on tool names and inputs.”[2] Before native schema support existed, the common trick was the reverse: define a tool whose input matches your desired data, then force the model to call it.
Structured-output features by provider
- OpenAI Structured Outputs ↗
The json_schema response format and strict mode, plus function-calling schemas.
- Anthropic Structured Outputs ↗
Claude's schema-constrained JSON output and strict tool use.
- OpenRouter Structured Outputs ↗
One JSON-schema interface across many models, with per-model support flags.
References
- Structured model outputs — OpenAI
- Structured outputs — Anthropic
- Structured Outputs — OpenRouter