What are structured outputs?
Skip this and your code is parsing prose, hoping a stray sentence before the JSON does not break the next step.
Structured outputs
JSON mode
Structured outputs are a model response constrained to match a schema you supply. Every field name, type and required value in the output is guaranteed. Your application reads the result directly, with no parsing step in between.
You define a schema once, usually JSON Schema, naming every field and its type. The model's decoding is then restricted at each step to tokens that keep the output valid against that schema. It cannot wander off into an explanation first.
That is different from asking nicely. A prompt that says "respond only in JSON" is a request the model usually honours and occasionally does not. A schema passed through a structured-outputs parameter is enforced by the decoding process itself.
JSON mode guarantees syntax. Structured outputs guarantee your schema
OpenAI shipped JSON mode first. Set response_format to json_object and the model returns text that parses as JSON. It says nothing about which keys appear or what type each value is. A required field can go missing and the response still counts as valid JSON.
Structured outputs closed that gap. OpenAI's structured outputs mode takes your JSON Schema and, with strict mode on, guarantees the response matches it exactly: every field present, every type correct. Anthropic's Claude reaches the same guarantee through tool calling, by defining one tool with the schema you want and forcing that tool's use.
The distinction matters because the failure modes are different. JSON mode fails on a missing or mistyped field, discovered wherever your code next reads it. Constrained structured outputs move that failure earlier, or remove it, at the cost of a schema you have to write and keep current.
- DefineJSON Schema with field names and types.
- ConstrainDecoding restricted to valid tokens.
- GenerateModel produces the matching shape.
- ParseYour code reads fields directly.
- ActFilters, a record, a downstream call.
Valid shape is not the same as a correct value. A required field can hold the wrong ship or the wrong date and still pass every check in this diagram.
Common questions
01Do structured outputs stop hallucination?
No. A structured output guarantees the shape of the response, not the truth of the values inside it. A model can return a syntactically perfect object with a fabricated order ID or a port that does not exist. You still need to validate values against your own data before acting on them.
02Is JSON mode the same as structured outputs?
No. JSON mode, OpenAI's older response_format: json_object setting, guarantees the output parses as JSON but not that it matches any particular schema. Structured outputs add a schema the response is constrained to match, so required fields and their types are guaranteed.
03How does Claude do structured outputs?
Claude uses tool calling for this. You define one tool whose input schema is the shape you want, then force the model to use that tool. The tool_use block that comes back carries arguments matching your schema, which is the same practical guarantee OpenAI's structured outputs mode gives.
04Should I still validate the response on my server?
Yes. A schema constrains the model's output, but an LLM API is still a network boundary. Parse the response through the same schema again on your server, the way you would validate any external input.

