Structured Outputs guarantee that LLM responses match your JSON schema through constrained decoding. Claude Opus 4.6, Sonnet 4.5, and GPT-5.2 support this feature. Instead of prompting and hoping, the model literally cannot produce non-conforming output. Use Pydantic (Python) or Zod (TypeScript) to define schemas, or the Instructor library for cross-platform support with 15+ LLM providers.
What Are Structured Outputs?
Structured Outputs solve a fundamental LLM problem: unreliable JSON responses. Before this feature, even careful prompting could produce malformed JSON, missing fields, or wrong types—breaking downstream systems and requiring retry logic.
With Structured Outputs, the model uses constrained decoding to guarantee schema compliance. GPT-5.2's Context-Free Grammar engine masks invalid tokens before generation—it literally cannot produce a non-conforming response. Claude uses similar constrained sampling with compiled grammar artifacts.
Which Models Support This?
As of February 2026, Structured Outputs are generally available on:
- Claude Opus 4.6 — GA on Claude API and Amazon Bedrock
- Claude Sonnet 4.5 — GA on Claude API and Amazon Bedrock
- Claude Opus 4.5 — GA on Claude API and Amazon Bedrock
- Claude Haiku 4.5 — GA on Claude API and Amazon Bedrock
- GPT-5.2 — Strict Mode with json_schema (JSON Mode is legacy)
"Structured outputs guarantee schema-compliant responses through constrained decoding: Always valid, type safe, no retries needed for schema violations."— Anthropic Claude Documentation
Getting Started: Installation
Install the SDK for your preferred provider:
pip install anthropic
pip install openai
pip install instructor
Using Pydantic (Python)
Define your schema with Pydantic, then use client.messages.parse() for automatic validation:
from pydantic import BaseModel
from anthropic import Anthropic
class ContactInfo(BaseModel):
name: str
email: str
company: str
client = Anthropic()
response = client.messages.parse(
model="claude-opus-4-6",
max_tokens=1024,
output_format=ContactInfo,
messages=[{"role": "user", "content": "Extract: John at [email protected] from Acme Inc"}]
)
print(response.parsed_output) # ContactInfo object
JSON Mode vs Structured Outputs
There's an important distinction:
- JSON Mode (
type: "json_object") — Guarantees valid JSON syntax only. No schema enforcement. Now considered legacy. - Structured Outputs (
type: "json_schema") — Guarantees valid JSON AND schema compliance. Production default in 2026.
With JSON Mode, you might get {"passengers": "2"} instead of {"passengers": 2}. With Structured Outputs, you always get the correct type.
Cross-Platform: The Instructor Library
Instructor provides a unified API for structured outputs across 15+ LLM providers including OpenAI, Anthropic, Google, Ollama, and DeepSeek. It handles schema transformation, automatic retries, and streaming.
import instructor
from pydantic import BaseModel
from openai import OpenAI
class User(BaseModel):
name: str
age: int
client = instructor.from_openai(OpenAI())
user = client.chat.completions.create(
model="gpt-5.2",
response_model=User,
messages=[{"role": "user", "content": "Extract: Jason is 25"}]
)
print(user.name, user.age) # Jason 25
Limitations to Know
While powerful, Structured Outputs have constraints:
- No recursive schemas — Self-referencing types aren't supported
- Limited numerical constraints —
minimum,maximum,multipleOfnot enforced - First request latency — Grammar compilation adds time on first use (cached for 24h)
- Refusals override schema — Safety refusals may produce non-conforming output