← AI Terminology
Structured Outputs / JSON Mode
Structured outputs (including JSON mode) constrain model completions to a schema — valid JSON, enums, or grammar-constrained fields — so downstream code can parse reliably.
Providers implement this via constrained decoding, schemas, or post-validation retries.
Providers implement this via constrained decoding, schemas, or post-validation retries.
Why It Matters in AI
Agents and apps need machine-readable results, not prose. Structured outputs eliminate brittle regex parsing and enable typed pipelines. They are table stakes for tool args, extraction, and UI forms.
Key Points
| Aspect | Description |
|---|---|
| Use | Extraction, routing, tool arguments, API responses |
| Tradeoff | Slight quality/latency cost for reliability |
| JSON mode | Guarantee JSON object syntax |
| Mechanism | Constrained decoding, CFG, or validate-and-retry |
| Providers | OpenAI strict schemas, Anthropic structured, Outlines/Guidance for open models |
| Schema mode | Match JSON Schema / Pydantic models exactly |
Simple Analogy
Filling a government form with fixed boxes instead of writing a free essay — the system can process every field automatically.
Common Usage Examples
response_format={type: json_schema, ...}- Instructor/Pydantic wrappers around LLM APIs
- Outlines/llama.cpp grammar sampling
- Extract invoice fields to typed dicts
Summary
In short: Structured outputs force model responses into schemas like JSON — making LLM results machine-parseable for real software.