Structured outputs
The model’s answer is constrained to match a JSON schema you provide.
Structured outputs is an API feature that forces the model’s answer to match a JSON schema you provide. Instead of asking for JSON and hoping, you pass a schema and the API guarantees the shape: required fields present, types correct, no broken syntax. Your code can parse it without regex and fragile retries.
Providers enforce the schema with constrained decoding: while generating, the model may only pick tokens that keep the output valid. OpenAI added Structured Outputs to its API in August 2024, and Anthropic documents JSON outputs and strict tool use in its structured outputs guide. The same mechanism can cover tool use arguments, so an agent cannot call a tool with a malformed request. There are limits: not every JSON Schema keyword is supported, and a model can still refuse or stop before finishing.
The content can still be wrong; only the format is guaranteed. A schema-valid invoice total can be a hallucinated number, so evals still compare field values with ground truth. Let the model fill in what it read, and keep arithmetic and final decisions in your own code, computed from the fields.
Sources
- OpenAI: Structured model outputs developers.openai.com
- Claude Docs: Structured outputs platform.claude.com
Related terms
- Tool use (function calling): The model returns a structured request to run a function you defined; your code runs it.
- Evals: A repeatable test set that scores an AI feature, so changes can be measured instead of guessed.
- Ground truth: The known correct answers or labels that a model’s output is compared against in an evaluation.
- Hallucination: A fluent, confident answer that is false or not supported by the sources.
- Golden dataset: A fixed set of real inputs with expected answers or checks, used to test an AI feature after every prompt or model change.
