Skip to content
AI Dev Toolkit.
Esc
  • Loading…

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.

Schema rules, as each provider documents them
RuleOpenAIAnthropicGemini
Every field in requiredYesNo (up to 24 optional parameters)Not stated
additionalPropertiesMust be falseMust be falseSupported
minimum / maximumSupported400 errorSupported
minLength / maxLengthNot listed400 errorNot listed
Size limits5,000 properties, 10 levels of nesting20 strict tools, 16 union-type parametersLarge 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

Related

All 41 terms in the AI glossary

Keep exploring