Lattice
Skip to content

Constrained decoding

Masking the token space during generation so the output can only be a valid instance of a schema, grammar or regex.

By Entry last reviewedmethod

What it implies

Unlike asking a model politely for JSON, this cannot be violated: there is no way to emit a token that would break the grammar. The trade is that constraining generation can make a model look worse at reasoning than it is, so never benchmark reasoning through it. Reach for it when downstream code cannot tolerate malformed output; use validation-and-retry when ergonomics matter more.

Tools in this index

Related terms

Rules of thumb

  • A definition is only useful next to the decision it changes. Read the linked layer to see where this term bites.
  • If a vendor's definition differs from this one, ask what it measures. Marketing definitions rarely name a number.
  • Every optimisation spends latency, memory or quality somewhere. Find out which before you turn it on.

Ask an AI about this page

Opens the assistant with this page’s link and a question already filled in.