Structured Outputs — Generally Available Across the Claude API
Anthropic has moved Structured Outputs to general availability across the Claude API, graduating the feature from its earlier beta status. Structured Outputs guarantees that Claude will return a response that is valid JSON conforming exactly to a developer-specified schema — eliminating the parsing failures, schema violations, and hallucinated field names that previously required defensive wrapper code in any application that needed reliable JSON from a language model.
How Structured Outputs works
Developers pass a JSON Schema alongside their request; Claude's output is guaranteed to match the schema or the API returns an error rather than an invalid response. This is enforced at the model level through constrained decoding, not post-hoc validation.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=[{
"role": "user",
"content": "Extract the key details from this invoice..."
}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "invoice",
"schema": {
"type": "object",
"properties": {
"vendor": {"type": "string"},
"amount": {"type": "number"},
"due_date": {"type": "string"}
},
"required": ["vendor", "amount", "due_date"]
}
}
}
)
What reaches GA
- JSON Schema support — full JSON Schema draft 2020-12 support including nested objects, arrays, enums, and optional fields;
anyOfandoneOfare supported for polymorphic schemas - Streaming-compatible — Structured Outputs works with streaming responses; partial JSON is streamed token by token and validated on completion
- All Claude 4.x models — available on Haiku 4.5, Sonnet 4.5, and Opus 4.5; not available on legacy 3.x models
- No beta flag required — the feature is now in the default API surface; existing beta users do not need to make any changes beyond removing the beta header from their requests
Migration from prompt-based JSON: If you currently use a system prompt instruction like "respond only with valid JSON matching this schema," switching to Structured Outputs will be strictly more reliable — the model-level enforcement eliminates the class of failures where Claude produces the right structure but adds explanatory text outside the JSON block.