AI engineering glossary · Prompt context engineering
What is grammar-constrained decoding?
Grammar-constrained decoding (also called Constrained decoding): A technique that limits, at each step of generation, which tokens are allowed so the whole output follows a formal grammar or pattern, such as a regular expression or JSON syntax. It guarantees a valid shape rather than hoping the model complies.
Grammar-constrained decoding: an example
A regex like '[0-9]{6}' forces the model to output only a six-digit Indian pincode.
Related terms
More Prompt context engineering terms
- Grounding
- In-context learning
- Instruction following
- Instruction hierarchy
- Instructor library
- JSON mode
- Least-to-most prompting
- Logit bias
Where you learn it
Grammar-constrained decoding is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.