Structured Outputs (OpenAI) / Constrained decoding — how do they differ from JSON mode?
hardAnswer
- JSON mode: guarantees valid JSON syntax.
- Structured Outputs / Constrained decoding: guarantees the JSON matches a specific schema (types, required fields, enums, nested structures).
- Implementation: build a grammar / automaton from the JSON schema and mask logits to only allow tokens that keep the output on a valid grammar path.
- OpenAI's Structured Outputs, XGrammar, Outlines.
- Standard for tool calling and complex extraction where schema violations would break downstream code.
Check yourself — multiple choice
- Same as JSON mode
- Constrained-decoding tracks a JSON-schema automaton → guarantees schema (not just syntax) → foundation for reliable tool calling
- Only post-processing
- Impossible
Structured Outputs / constrained decoding: schema-level guarantees, not just JSON syntax.
#generation#production
Practise LLMs & GenAI
214 interview questions in this topic.