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.

Level: advancedTopic: Prompt context engineering

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

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.