Constrained Decoding
Restricting a model's next-token choices to those a formal grammar permits.
Constrained decoding forces a model's output to conform to a formal grammar by masking, at each step, the tokens that could not continue a valid string. It is what makes Structured Output reliable rather than hopeful: the model cannot emit malformed JSON because malformed continuations are not available to it.
The grammar has to be compiled from the schema, and that compilation has real costs and real limits — which show up as production constraints rather than theory.
Cost is driven by breadth, not size. A flat enumeration with dozens of members is cheap; a discriminated union of a dozen object types is expensive, because the compiler pays per alternative. Trimming fields inside a union member does not help; removing a member does.
Optional properties are budgeted. Providers impose ceilings on the number of optional parameters in a schema, and a nested union that inlines the same alternatives twice pays twice. Adding one optional field to a leaf can push a whole phase over the limit, and the failure is a rejection before inference — fast, total, and unrelated-looking.
Compilation itself can time out on large schemas, sometimes for schemas that are byte-identical to ones that compile fine, depending on how they were constructed.
The practical rule: measure the compiled schema, not the source. See JSON Schema.
See also6
Hand-picked in the note itself — the neighbours worth reading next.
Structured Output
Constraining a model to emit data conforming to a declared schema rather than free text.
Agents & Language Models11 connections
Schema Validation
Checking data against a declared shape at runtime, and using the result as the typed value.
Agents & Language Models11 connections
Model Routing
Choosing which model handles which step, trading capability against cost and latency.
Agents & Language Models9 connections
Token
The sub-word unit a language model actually reads and writes; the unit of cost and of context.
Agents & Language Models13 connections
Prompt Engineering
Shaping a model's input to make the desired behaviour reliable rather than occasional.
Agents & Language Models18 connections
Guardrail
A rule constraining what a model may do, enforced by prompt, schema, or surrounding code.
Agents & Language Models13 connections
Related2
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from7
Notes elsewhere in the wiki that reach for this one.
- GuardrailAgents & Language Models
A rule constraining what a model may do, enforced by prompt, schema, or surrounding code.
- JSON SchemaAgents & Language Models
A vocabulary for describing the shape of JSON data, and the lingua franca of model tool interfaces.
- Model RoutingAgents & Language Models
Choosing which model handles which step, trading capability against cost and latency.
- Prompt EngineeringAgents & Language Models
Shaping a model's input to make the desired behaviour reliable rather than occasional.
- Schema ValidationAgents & Language Models
Checking data against a declared shape at runtime, and using the result as the typed value.
- Structured OutputAgents & Language Models
Constraining a model to emit data conforming to a declared schema rather than free text.
- TokenAgents & Language Models
The sub-word unit a language model actually reads and writes; the unit of cost and of context.