cs.CLSep 30, 2026

Provably Tractable NFA-Constrained Language Generation via HMMs

Authors: Jialiang Sun, Kuldeep Meel

Organizations: University of Toronto

Abstract

Constrained generation aims to sample from language models (LMs) conditioned on hard constraints. Existing constrained-generation techniques for nondeterministic finite automaton (NFA) constraints either distort the distribution or sacrifice efficiency. Theoretically, this task reduces to counting the length-nn sequences accepted by an NFA (#NFA), and the exact #NFA problem is #P-complete. Recent work has shown that #NFA admits a fully polynomial randomized approximation scheme (FPRAS). Inspired by this result, we propose NFA-LM, a polynomial-time engine for NFA-constrained generation with theoretical guarantees under mild assumptions. Experiments show that NFA-LM efficiently generates high-quality outputs with theoretically bounded approximation error.

Figures & tables

Appendix figures & tables1 asset

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Suffix-Constrained Greedy Search Algorithms for Causal Language Models

    Mar 1, 2026Ayoub Hammal, Pierre Zweigenbaum, Caio CorroLarge Language Model GenerationData Generation

  2. Mistake-Bounded Language Generation

    May 11, 2026Jon Kleinberg, Charlotte Peale, Omer ReingoldConvergenceLogarithmic Scaling