Generative language models produce outputs from a conditional probability distribution over a vocabulary. In regulated domains — finance, healthcare, legal, and defense — the support of this distribution includes tokens that, while linguistically valid, constitute compliance violations. Post-hoc filtering is insufficient: by the time a prohibited token is generated, the model has already allocated computational resources and the output may already be visible to users. Constrained decoding addresses this at the generation step itself, modifying the token selection procedure to guarantee that outputs satisfy a formal specification.

We present a taxonomy of constrained decoding methods for regulatory compliance, evaluate their computational properties, and provide benchmarks on real-world compliance tasks across three regulated domains.

Formal Framework: Generation Under Constraints

Let V denote the vocabulary, and let P(xt | x) be the conditional distribution produced by a language model at step t. Unconstrained decoding selects xt ∼ P. Under constrained decoding, we define a constraint function C : V* → {0, 1} that evaluates whether a partial or complete sequence satisfies the regulatory specification. The constrained selection rule is:

xt = argmaxv ∈ V P(v | x) · 𝟙[C(x ⊕ v) = 1]

This formulation admits multiple implementation strategies. The three dominant approaches in production systems are automata-guided decoding, SMT-based token masking, and weighted grammar constraints.

Automata-Guided Decoding

Regulatory specifications are compiled into deterministic finite automata (DFA) over the token vocabulary. At each decoding step, the DFA state transition function δ(qt, v) determines whether token v is legal from current state qt. Tokens for which δ is undefined are masked from the logits. This approach is used in the Google SELENE framework and the Guidance library, which compile JSON Schema and CFG specifications into token-level DFAs.

SMT-Based Constraint Solving

For constraints that cannot be expressed as regular languages — numerical bounds on generated quantities, string-length limits, or cross-field consistency rules — satisfiability modulo theories (SMT) solvers are invoked at decoding boundaries. A constraint graph is maintained as tokens are generated, and the solver checks whether a completion exists before permitting greedy or sampled selection.

Benchmark: Compliance Constraint Types