AI glossary · Agents and tools
What are structured outputs in LLM APIs?
Also called: structured output, JSON Schema output, strict mode
Definition
Structured outputs is an LLM API feature that constrains the model’s reply to a JSON Schema you supply, so the response parses and has the fields and types you asked for, unlike JSON mode, which only promises valid JSON.
Explained
How do structured outputs work?
The guarantee comes from constrained decoding: while the model writes, tokens that would break the schema are never chosen. If you can’t turn it on and replies arrive broken, our guide to fixing invalid JSON from LLMs covers the repair side.
You send a schema with the request: text.format with type: "json_schema" and strict: true in OpenAI’s Responses API, output_config.format in Anthropic’s Messages API, and response_format with a schema in Gemini. Generation is then restricted to output that fits. Anthropic notes that the first request with a new schema is slower while its grammar compiles, and that compiled grammars are cached for 24 hours.
The guarantee has documented gaps. If the model refuses, or the reply hits the max output tokens limit, the output may not match the schema, so check for a refusal or an incomplete status (OpenAI) or the stop_reason (Anthropic) before parsing. Anthropic also notes that the capitalisation of enum values isn’t guaranteed. And every provider supports only part of JSON Schema.
Example
One schema, three sets of rules
A schema that works on one provider can fail on another. OpenAI requires every field to be listed in required (make one optional with a union such as ["string", "null"]) and supports minimum and maximum. Anthropic returns a 400 error for numeric limits such as minimum. Gemini accepts them but warns that very large or deeply nested schemas may be rejected.
Structured outputs also don’t check that values are true. A schema guarantees an email field holding a string, not the right email, so validate the content, and watch for hallucinated values in fields the source never mentioned.
| Rule | OpenAI | Anthropic | Gemini |
|---|---|---|---|
Every field in required | Yes | No (up to 24 optional parameters) | Not stated |
additionalProperties | Must be false | Must be false | Supported |
minimum / maximum | Supported | 400 error | Supported |
minLength / maxLength | Not listed | 400 error | Not listed |
| Size limits | 5,000 properties, 10 levels of nesting | 20 strict tools, 16 union-type parameters | Large or deep schemas may be rejected |
From the OpenAI, Anthropic and Gemini structured output docs, 2026-10-11. “Not listed” means the docs don’t name it as supported.
Cost and quality
Why use structured outputs instead of asking for JSON?
Without a schema, replies can come back malformed or missing fields, and each one costs a retry or a parser crash. With structured outputs on, you handle the documented edge cases (refusal, truncation) instead of guessing at broken JSON.
Don’t mix up
What is the difference between structured outputs and JSON mode?
- Structured outputs vs JSON mode
- OpenAI’s JSON mode (
type: "json_object") guarantees only that the output parses, not that it matches any schema, and the API returns an error unless the word “JSON” appears somewhere in the context. OpenAI calls Structured Outputs the evolution of JSON mode. - Structured outputs vs function calling
- Both use JSON Schema. Function calling shapes the arguments of a tool call your code will run; structured outputs shape the reply itself. Anthropic’s strict tool use (
strict: true) is the structured outputs guarantee applied to tool arguments.
FAQ
Questions people ask
Do structured outputs guarantee correct answers?
No. They guarantee the shape of the reply: valid JSON with the required fields and types. The values can still be wrong, invented, or empty strings that satisfy the schema. Validate values in code, use enums where you can, and allow a value such as “unknown” so the model is not pushed to make data up. A reply cut off by max output tokens can still be incomplete.
Which providers support structured outputs?
OpenAI, Google Gemini and Anthropic all offer schema-constrained output; on Anthropic’s API it is generally available through output_config.format, with no beta header. Open-model servers support it too: vLLM’s OpenAI-compatible server has it on by default. Each supports a different subset of JSON Schema, so a schema that works on one provider may be rejected on another.
Is function calling the same as structured outputs?
They use the same machinery but serve different jobs. Function calling asks the model to choose a tool and fill in its arguments, which your code then runs. Structured outputs shape the model’s final answer to your schema. Use function calling when the model should act, and structured outputs when you only need data back in a fixed format, such as fields extracted from a document.
Go deeper
Try it and read more
- Free toolJSON RepairFix broken JSON from LLM output.
- Free toolChat Format ConverterConvert messages between OpenAI, Anthropic and Gemini.
- Free toolPrompt Template LibraryPrompt templates for code review, tests, docs, SQL, RAG and LLM evals.
- Guide · 13 min readWhy LLMs return invalid JSON, and how to stop itWhy LLMs return invalid JSON and how to stop it: structured outputs, schema validation with Zod or Pydantic, retries, safe repair and streaming partial JSON.
Related