Structured data and JSON code visualization

Structured Outputs: How to Get Guaranteed JSON from ChatGPT and Claude

No more JSON.parse() errors. Structured Outputs use constrained decoding to guarantee schema-compliant responses from LLMs every time.

LORIS.PRO Feb 11, 2026 7 min read

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.

100% Schema Compliance
0 JSON.parse() Errors
15+ LLM Providers (Instructor)

Which Models Support This?

As of February 2026, Structured Outputs are generally available on:

Source
"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:

ANTHROPIC (CLAUDE)
pip install anthropic
OPENAI (GPT)
pip install openai
INSTRUCTOR (CROSS-PLATFORM)
pip install instructor

Using Pydantic (Python)

Define your schema with Pydantic, then use client.messages.parse() for automatic validation:

PYTHON + PYDANTIC
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:

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.

INSTRUCTOR EXAMPLE
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:

FAQ

What are Structured Outputs in LLMs?
Structured Outputs use constrained decoding to guarantee that LLM responses match a specified JSON schema. Instead of hoping the model produces valid JSON, the decoding engine literally cannot produce non-conforming tokens. This eliminates JSON.parse() errors and schema validation failures.
Which models support Structured Outputs?
Claude Opus 4.6, Claude Sonnet 4.5, Claude Opus 4.5, and Claude Haiku 4.5 support Structured Outputs (GA). OpenAI's GPT-5.2 supports Strict Mode with json_schema. Both use constrained decoding rather than post-hoc validation.
What is the difference between JSON Mode and Structured Outputs?
JSON Mode (type: json_object) only guarantees valid JSON syntax—it doesn't enforce schema adherence. Structured Outputs with json_schema guarantee both valid syntax AND schema compliance. In 2026, JSON Mode is considered legacy; Strict Mode is the production default.