Grammar-Constrained Generation
An approach where LLM generation is constrained by a formal grammar. The model can only produce token sequences that adhere to the rules — for example, valid JSON or SQL.
Why
- to guarantee the validity of the response without post-processing;
- to exclude unnecessary text around the structure;
- to reliably prepare data for parsers and APIs.
Relation to Structured Decoding
This is a special case of Structured Decoding: grammar is one way to define constraints.