A ai coolAId

Constrained Decoding & Schema Drift

In One Sentence
Enforcing exact grammar or JSON schema rules at inference time by masking invalid tokens, preventing models from hallucinating fake fields or enums in long outputs.
ELI5 (Intuition)
Putting bumper rails on a bowling lane: even if the AI gets distracted halfway through a long JSON file and tries to invent a fake keyword, the rails physically block invalid tokens.
ELI18 (Technical)
As generation length grows, unconstrained models suffer schema drift (falling back on linguistic priors to invent plausible-sounding fake enums). Grammar/FSM-constrained decoding compiles a JSON Schema or CFG into a finite-state mask setting invalid token logits to \(-\infty\) before Softmax.
In Practice
Production LLM pipelines use Structured Outputs (strict: true), Outlines, xgrammar, or llguidance so tool calls and database writes achieve 100% schema validity without brittle regex retries.