Structured outputs

Structured outputs make the model emit data that matches a JSON Schema, so downstream code can parse it without retries. “JSON mode” (valid JSON only) is weaker: OpenAI’s docs say only Structured Outputs ensure schema adherence. Anthropic describes its version as grammar-based constrained decoding.

VendorHowNotes from docs
OpenAItext.format = json_schema with "strict": true; also strict in function callingAvailable from gpt-4o-2024-08-06 and later; refusals arrive as a distinct refusal item, detectable in code; some schema features unavailable
Anthropicoutput_config.format = json_schema, plus strict: true on toolsGA on current Claude models (Opus 5.5, Sonnet 5.5, Fable 5.1 and others) and on Bedrock, Google Cloud and Foundry
Google Geminiresponse_format with mime_type: application/json and a schema; Pydantic/Zod supportedSupports a JSON Schema subset including minimum/maximum, prefixItems; very large or deeply nested schemas may be rejected; docs tell you to validate values in your app

Anthropic limits worth knowing

Not supported: recursive schemas, numeric constraints (minimum/maximum), string length constraints, minItems above 1, external $ref URLs, complex regex. At most 20 strict tools, 24 optional parameters and 16 union-typed parameters per request. The first request pays grammar-compilation latency; compiled grammars are cached 24 hours. Changing the format invalidates the prompt cache (prompt-caching). Output can still be invalid on a refusal or max_tokens stop.

Caveats (all vendors)

  • Schema-valid does not mean correct: values can be wrong. Validate and evaluate (llm-as-judge-and-evals).
  • Not the same thing as MCP structuredContent/outputSchema, which describes tool results (tool-description-design).
  • With Claude 4.6 and later, prefilling the answer with { is no longer available; Anthropic’s migration advice points to structured outputs instead (prompting-reasoning-models).

Sources