Structured output: getting AI answers in a format you can trust
Structured output is an AI model's answer produced in an enforced format, most often a JSON object that follows a schema defined in advance. The goal is for your program to read the answer without workarounds or format errors.
Data as of October 22, 2026
Key figures
| Level | Intermediate |
|---|
How it works in practice
Left unconstrained, a language model writes free text. Even if your prompt says “reply in JSON”, it may add an opening sentence, skip a field or leave a bracket open, and your code breaks.
With structured output, you pass a schema through the API. The provider then restricts generation so that every token produced stays compatible with that schema. Anthropic calls this constrained decoding; the schema’s grammar is compiled on the first request, which adds a little latency to that first call. The same mechanism can apply to tool calling arguments in strict mode.
A concrete example
An accounting firm receives hundreds of invoices as PDFs. It asks the model to extract an object like this for each one: supplier (text), date (text in YYYY-MM-DD format), total_amount (number), currency (one of EUR, USD, GBP). With structured output, every answer has exactly those four fields and can go straight into a spreadsheet. The firm still needs to spot-check that the extracted amounts are right.
To write clear instructions to go with the schema, our prompt generator can help.
Why it matters
This is what turns a chatbot into a dependable piece of software: data extraction, automatic classification, form filling, hand-offs between several AI agents. A guaranteed format also makes it easier to add automatic checks downstream.
Common mistakes and myths
- “Guaranteed format means accurate content.” The model can still hallucinate a value, just in the right format.
- “The schema is followed 100% of the time.” Anthropic flags two exceptions: a refusal by the model or an answer cut off by the token limit can produce non-conforming output. Your code has to handle both.
- “Asking for JSON in the prompt is enough.” It often works, but with no guarantee. Structured outputs enforce the format during generation.
- “Any schema will do.” Only part of JSON Schema is supported, so check your provider’s documentation.
Related terms
- Tool calling (function calling) · The ability of an AI model to request that an external function be run with specific arguments, then use the result in its answer.
- API · An interface that lets one program send requests to a service, such as an AI model, and get its responses back automatically.
- Hallucination · An AI answer that sounds confident and plausible but is false or made up: a figure, a quote, a source or a reference.
- Prompt engineering · The practice of writing, testing and refining instructions to an AI model so its answers become more reliable and useful.
- System prompt · Background instructions given to a model before the conversation starts (role, tone, rules) that shape every answer that follows.
- AI agent · An AI that does more than answer: it plans and carries out a series of actions with tools to reach a goal you set.
Try it
Full glossary
Frequently asked questions
How is it different from plain JSON mode?
OpenAI's documentation draws the line clearly: JSON mode only guarantees valid JSON, while structured outputs also guarantee that the response follows the schema you supplied, with the right fields and types.
How long has this feature been around?
Constrained generation techniques already existed in research projects and libraries. Among the major APIs, OpenAI launched Structured Outputs on 6 August 2024, and Anthropic also offers structured outputs in its Claude API.
Is the answer guaranteed to be correct?
No. The format is guaranteed, the content is not. Anthropic's documentation says so explicitly: perfectly valid JSON can still hold an inaccurate value, so important data should always be checked.
Is every JSON Schema accepted?
No. Providers support only part of the JSON Schema standard. Anthropic, for example, notes that recursive schemas and some numeric constraints are not supported.
Data sources
Data as of October 22, 2026
Report an error
Does a figure, a date or a fact look wrong? Tell us: every report is checked.