Structured Output
Forcing an AI to respond in valid JSON or a specific schema — every time.
Structured output (also called JSON mode or schema-constrained generation) forces a model to produce output that conforms to a specified format — valid JSON, a particular schema, or a defined set of fields.
Why it matters for production systems: Parsing a model's prose response is fragile. If the model says "The sentiment is positive" one time and "Positive." the next, downstream code breaks. Structured output removes that fragility.
How it works technically: Providers use constrained decoding — at each token step, only tokens valid for the current position in the schema are permitted. This guarantees syntactic validity without any retry logic.
Using it:
- Anthropic: Return a tool call with a precisely defined input schema — the model fills the schema fields
- OpenAI:
"response_format": {"type": "json_schema", "json_schema": {...}} - Ollama/local:
"format": "json"+ schema in the prompt
Limitations: The model must still generate semantically correct content. Structured output guarantees {"sentiment": "positive"} is valid JSON; it doesn't guarantee "positive" is accurate.
In plain terms
A form with mandatory fields vs. a blank page. The form guarantees you get a name, date, and signature in the right boxes — not that the name is correct.