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 Lattice editorial · Entry last reviewed · method

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