the.ai

Structure / Decoding

verified

Grammar-Constrained Decoding

At every step, work out which tokens could still lead to a valid output and set the probability of all the others to zero. The model can then only produce something the grammar accepts — not usually, but always, because the invalid continuations were never on the table.

Viz primitive · budget-splitmasked-tokens = 20

masked-tokens holds 33% of the budget; rest holds the remaining 67%.

Vocabulary entries the grammar forbids at this position, against the ones it still allows, in tokens. Drag the grammar's strictness up to watch almost everything be masked — the survivors keep their relative probabilities, and the sequence the model wanted may not be among them.

20

Reviewed by opendroid · 2026-08-18

  • arXiv:2307.09702 — Efficient Guided Generation for Large Language Models
  • arXiv:2403.06988 — Guiding LLMs The Right Way: Fast, Non-Invasive Constrained Generation