Comparison · Agents, APIs & MCP
Structured Outputs Compared: OpenAI, Claude, Gemini, Mistral
OpenAI, Claude, Gemini and Mistral can all force JSON that matches a schema, but each accepts a different subset of JSON Schema and fails differently. Here's how they compare and how to write one schema that works on all of them.
Pavel Holmgren · Nov 22, 2026 · 10 min read
Documentation-based research
On this page

Every major LLM API can now force a response to match a JSON Schema, but they don't accept the same schemas or fail in the same way. OpenAI makes you mark every field required, Claude rejects recursive schemas and numeric bounds, and Gemini silently drops length limits. This guide compares structured outputs on OpenAI, Claude, Gemini and Mistral, plus self-hosted options, and shows how to write one schema that survives all of them.
Everything below comes from each provider's official documentation as of Nov 22, 2026. Request shapes are abbreviated and illustrative; the only code we ran is the local validation check described later, which makes no model calls.
JSON mode, structured outputs and strict tools
Three features get lumped together as "JSON output", and the difference matters. JSON mode only promises that the output parses: any keys, any types. Structured outputs (also called schema-constrained or grammar-constrained decoding) limit generation to tokens that keep the output valid against your schema, so required fields and types come back as declared. Strict tool use applies the same constraint to the arguments of a function or tool call instead of the final answer.

Rule of thumb from the vendors themselves: use a response schema when you want the model's answer in a fixed shape (extraction, classification, UI payloads), and strict tool or function calling when the model needs to call your code. OpenAI, Anthropic and Google all draw that line in their docs, and Claude and OpenAI let you use both in one request. None of them treats the schema as a substitute for checking the values in your own code.
Structured outputs by provider at a glance
Scroll the table horizontally on smaller screens.
| Provider | How to enable | Tool-call equivalent | Hard limits | Watch for |
|---|---|---|---|---|
| OpenAI | Responses: text.format type json_schema with strict true. Chat Completions: response_format type json_schema | strict: true on functions; Responses tries strict by default, Chat Completions does not | All fields required, additionalProperties false, root must be an object; 5,000 properties, 10 nesting levels, 1,000 enum values | refusal field; truncated output at the token limit |
| Anthropic Claude | output_config.format type json_schema (Messages API, all models) | strict: true on tool definitions | 20 strict tools, 24 optional parameters, 16 union-typed parameters per request; no recursion | stop_reason refusal or max_tokens; enum capitalization not guaranteed |
| Google Gemini | Interactions API response_format: type text, mime_type application/json, plus schema | Structured output with built-in tools and function calling (preview, Gemini 4 and 3 series) | Schemas over internal state limits get 400 INVALID_ARGUMENT | Length and count constraints silently ignored |
| Mistral | response_format type json_schema with name, schema and strict true | Function calling (separate feature) | All current models except codestral-mamba; no published keyword list | Schema is also injected into the system prompt |
OpenAI: strictest schema rules, widest keyword support
On the OpenAI API, Structured Outputs is the evolution of JSON mode: both return valid JSON, but only Structured Outputs guarantees schema adherence. In the Responses API you pass the schema in text.format with type: "json_schema" and strict: true; Chat Completions uses response_format. OpenAI says the feature works on models from GPT-4o onward, and recommends it over JSON mode whenever it's available. It first announced the feature in August 2024.
The catch is the opt-in contract. Every object needs additionalProperties: false, every property must be listed in required, and the root must be an object rather than an anyOf. Optional fields are emulated with a union that includes null. A schema can hold up to 5,000 object properties across 10 levels of nesting and 1,000 enum values in total. In return OpenAI supports more of JSON Schema than the others: pattern, format, minimum/maximum, multipleOf, minItems/maxItems, anyOf, definitions and recursive schemas all work. allOf, not and if/then/else are not supported, and keys come back in schema order.
For tools, strict mode on function definitions uses the same machinery. If you omit strict, the Responses API tries to normalize your schema into strict mode and falls back to best-effort calling when it can't; Chat Completions stays non-strict by default. JSON mode still exists (type: "json_object"), but the request fails if the word "JSON" doesn't appear anywhere in the context, a guard against runaway whitespace output. On supported GPT-6 and later models, the Responses API can also switch schemas mid-conversation with a configuration_update input item.
Claude: compiled grammars with hard complexity caps
Claude's structured outputs work on all models through the Messages API, no longer behind a beta header,, on the Claude API, Amazon Bedrock, Claude Platform on AWS, Google Cloud and Microsoft Foundry. You pass the schema in output_config.format; the beta output_format parameter is deprecated and now returns a 400 unless you send the old structured-outputs-2025-11-13 beta header. Strict tool use is a separate strict: true flag on each tool. Managed Agents doesn't support the feature.
Anthropic compiles each schema into a grammar. The first request with a new schema is slower while it compiles; the result is cached for 24 hours from last use. Changing the schema structure, or the set of tools in a combined request, invalidates that cache, and changing output_config.format also invalidates the prompt cache for the conversation. The API adds a system prompt describing the format, so input tokens rise slightly.
The supported subset is narrower than OpenAI's. Recursive schemas, oneOf, not, numeric bounds, string length limits and array constraints beyond minItems of 0 or 1 are rejected with a 400. Regex pattern works for simple expressions. The official SDKs soften this: client.messages.parse() moves unsupported constraints into field descriptions, sends the simplified schema, then validates the response against your original model. There are also explicit per-request caps: 20 strict tools, 24 optional parameters and 16 parameters with union types, counted across every strict schema in the request, plus a 180-second compilation timeout.
Two quirks are easy to miss. Required properties come back first, then optional ones, regardless of schema order. And Anthropic says enum values may differ from your schema in capitalization (for example a capital letter after a space) with no error, so compare enums case-insensitively. Structured outputs also can't be combined with Citations (400 error) or message prefilling, but they do work with streaming and with batch processing at its 50% discount.
Gemini: permissive schemas, silent stripping
The Gemini API documents structured outputs on its Interactions API: set response_format to type: "text" with mime_type: "application/json" and a schema. The Google Gen AI SDKs accept Pydantic and Zod models. Supported keywords include enum, string format (such as date-time, date and time), minimum/maximum, prefixItems for tuples, minItems/maxItems, nullable types via a type array, and additionalProperties as either a boolean or a schema. Google's own examples use anyOf and recursive structures.
The difference that bites in production: minLength, maxLength, minProperties, maxProperties, uniqueItems and the contains family are not enforced. Gemini strips them during request normalization instead of returning an error, which means a Pydantic Field(max_length=...) looks honored but isn't. If a schema is too complex for the decoding state machine, the request fails with 400 INVALID_ARGUMENT; Google suggests flattening nesting, trimming enums and optional fields, and moving soft rules into descriptions.
Streaming returns valid partial JSON chunks you can concatenate. Combining structured output with built-in tools such as Google Search grounding, URL context, code execution, File Search and function calling is in preview for Gemini 4 and Gemini 3 series models. For yes/no probabilities or single-choice classification, Google points to a separate product, which we covered in our Gemini Decisions API analysis.
Mistral, vLLM and Ollama
Mistral uses an OpenAI-style shape: response_format with type: "json_schema" and a json_schema object holding name, schema and strict: true, or client.chat.parse() with a Pydantic model in the Python SDK. Custom structured outputs and JSON mode work on all currently available models except codestral-mamba. Mistral also prepends a line to the system prompt telling the model to follow the schema, and recommends describing the expected output in your own prompt too. Its docs don't publish a supported-keyword list or complexity limits, so test unusual schemas before relying on them.
If you serve open-weight models yourself, vLLM supports structured outputs on its OpenAI-compatible server through a structured_outputs parameter that accepts json, regex, choice, grammar or structural_tag, using xgrammar or guidance as the backend. The old guided_json-style fields were removed in v0.12.0, and the lm-format-enforcer backend is deprecated from v0.33.0. Ollama takes a schema in the `format` field of a local request, but notes that its cloud doesn't support structured outputs yet. Our local LLM JSON guide walks through that setup, and our vLLM vs SGLang vs TensorRT-LLM comparison covers the serving side.
Writing one schema that works everywhere

If your app may switch providers, or routes through a gateway, design for the intersection of the three rulebooks and enforce the rest in code:
- Make every property required and express optional values as nullable. That satisfies OpenAI strict mode and avoids Claude's 24-optional-parameter cap, but each nullable field counts toward Claude's limit of 16 union-typed parameters.
- Set `additionalProperties: false` on every object. OpenAI and Claude require it, and Gemini accepts it.
- Keep length, range and uniqueness rules out of the decoding schema. Claude's API rejects them, Gemini ignores several, so enforce them in your validator.
- Avoid recursion, `oneOf`, `allOf` and `not`. Use
anyOffor unions and flatten deep trees. - Never rely on key order or enum capitalization. Parse into an object and normalize enum strings before comparing.
- Use real types, not free-form maps. Claude's SDK sends a Python
dictfield as an object with no properties, so the model can only return{}for it; list keys explicitly or use an array of key-value pairs.
Here's the kind of model we mean, written with Pydantic so the same class generates the schema and validates the response:
from typing import Literal, Optionalfrom pydantic import BaseModel, ConfigDictclass Ticket(BaseModel): model_config = ConfigDict(extra="forbid") # additionalProperties: false category: Literal["billing", "bug", "feature_request", "other"] priority: Literal["low", "normal", "urgent"] summary: str order_id: Optional[str] # required key, value may be null
What we checked: we generated this schema locally with Pydantic 2.14 and validated it as JSON Schema 2020-12 with the jsonschema library. Every property is listed as required, additionalProperties is false, and order_id is the only union-typed field. We then ran four hand-written responses through the model: a correct object passed; "Billing" with a capital B, a missing field, and an extra reasoning field each failed; the capitalized enum passed after lowercasing. This is a deterministic code test with no model calls. It shows the validator catches the failure modes the providers document, not how often any model produces them.
Failure modes to handle in code
- Refusals. OpenAI adds a
refusalfield; Claude returnsstop_reason: "refusal"with a 200 status, billed tokens and output that may not match the schema. Check before parsing. - Truncation. Hitting the output token limit can cut the JSON off mid-object on every provider. Treat incomplete responses as failures and retry with a higher limit, not a looser schema.
- Valid shape, wrong facts. A schema can't tell a correct total from a wrong one. Our structured output validation lesson covers checking citations and business rules after parsing.
- First-request latency. Claude compiles a grammar for each new schema and caches it for 24 hours from last use, so generating schemas dynamically per request costs latency. OpenAI documents a similar first-request delay for fine-tuned models.
- Schema data retention. Anthropic caches compiled schemas separately from prompts and says protected health information must not appear in schema names, enums or patterns.
Verdict
If you're on a single provider, use its native structured outputs, not JSON mode: OpenAI's strict json_schema, Claude's output_config.format, Gemini's response_format schema or Mistral's json_schema with strict. Use the official SDK helpers, which keep your types and schema in sync and, on Claude, transform constraints the API can't enforce.
If you support more than one provider, write a deliberately boring schema: flat objects, every field required and nullable where optional, additionalProperties: false, enums instead of free text, and no length or range keywords. Put the real business rules in a Pydantic or Zod validator that runs on every response, whatever the API promises. Structured outputs remove parsing errors; they don't remove the need to check the answer.
Sources
- OpenAI: Structured model outputs guide
- OpenAI: Function calling, strict mode
- Anthropic: Claude structured outputs
- Anthropic: Strict tool use
- Google: Gemini API structured outputs
- Mistral: Custom structured outputs
- Mistral: JSON mode
- vLLM: Structured outputs
- Ollama: Structured outputs
- OpenAI: Introducing Structured Outputs in the API (Aug 2024)
Tools covered in this guide
Frequently asked questions
- What is the difference between JSON mode and structured outputs?
- JSON mode only guarantees that the response parses as JSON; keys and types can be anything. Structured outputs constrain generation to a JSON Schema you supply, so required fields, types and enum values come back as declared, within the schema subset each provider supports.
- Does Claude support structured outputs?
- Yes. Anthropic's structured outputs are available on all Claude models through the Messages API using output_config.format with a JSON schema, plus strict: true on tool definitions. They are also available on Amazon Bedrock, Google Cloud and Microsoft Foundry, but not in Managed Agents.
- Why does OpenAI require all fields to be required in structured outputs?
- OpenAI's strict mode only generates the keys you list, so it requires every property to appear in required and every object to set additionalProperties to false. To make a field optional, give it a union type that includes null.
- Do structured outputs guarantee correct answers?
- No. They guarantee the shape of the response, not its accuracy. Responses can still be refused, cut off at the token limit or factually wrong, and Gemini ignores some constraints such as maxLength, so validate every response in your own code.
- Can I use the same JSON schema for OpenAI, Claude and Gemini?
- Usually, if you keep it simple: an object root, every field required with null for optional values, additionalProperties false, no recursion, and no length or numeric range keywords. Enforce those extra rules with Pydantic or Zod after parsing.