AI Glossary Term

What does “Guarded Decoding” mean?

Definition

A generation strategy that constrains output tokens to valid structures or policy-compliant choices.

How Guarded Decoding works

Diagram for Guarded Decoding, steps in order: Model scores next tokens; then Rule masks invalid or disallowed tokens; then Sample from what remains; then Output always fits the rules.Model scores next tokensRule masks invalid or disallowedtokensSample from what remainsOutput always fits the rules

Example

To get valid JSON, the decoder blocks any token that would break the required structure at each step. The model can only choose among tokens that keep the output well formed.

Why it matters

It guarantees output formats or policies without relying on the model to behave. It can limit expression if the rules are too tight.

Common questions

Is it the same as a safety filter?

Related. A filter checks text after it is written; guarded decoding limits choices while writing.

Does it slow generation?

A little, since constraints are checked at each step.

What else can it enforce?

Grammars, lists of allowed words, or blocked terms.

Learn more in our free guides

Test yourself

See also