Structured-output tools live at three layers: decoding (Outlines, GBNF, provider-side), application (Pydantic + retry), and compile-time (BAML). The layer determines what guarantees you get.
Imagine three ways to stop a typo in an essay. The first is a magical pen that physically refuses to write any letter that would create a typo (decoding-layer). The second is a kind editor who reads every sentence and asks you to rewrite it if a typo slipped through (application-layer). The third is a typewriter that was built with your specific essay's vocabulary hard-coded into its keys, so only valid words can be typed (compile-time codegen). All three prevent typos in the final essay; they just do it at very different moments.
Detailed answer & concept explanation~9 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6 min: three-layer taxonomy + decoding-layer mechanisms (FSM, GBNF, provider-side) + application-layer retry + compile-time codegen + production stack combining layers + when constrained decoding hurts.
Real products, models, and research that use this idea.
- OpenAI Structured Outputs first shipped in 2024 and by 2026 is the default for production extraction workloads on gpt-5.5 and the o5 reasoning family.
- BAML adoption in 2025-2026 grew in TypeScript-heavy teams that wanted typed clients and compile-time schema checking.
- Outlines is the standard pick for self-hosted Llama 4 Maverick and DeepSeek V4 deployments where decoding-layer constraints are needed.
- Llama.cpp's GBNF grammars are widely used in local-inference pipelines (LM Studio, Ollama-adjacent tooling) for structured output on consumer hardware.
- Anthropic's Claude Opus 4.7 supports structured output through its tool-calling shape; for Claude users this is the closest analogue to OpenAI Structured Outputs.
What an interviewer would ask next. Try answering before peeking at the approach.
QWalk through what an FSM-constrained decoding step actually does mechanically.
QWhy does OpenAI's `response_format={'type': 'json_object'}` not give the same guarantee as Structured Outputs?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating Outlines, BAML, and OpenAI Structured Outputs as substitutes that solve the same problem at the same layer. They are stacked layers, not alternatives; a production stack often uses more than one.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.