ABS: Enforcing Constraint Satisfaction On Generated Sequences Via Automata-Guided Beam Search
Vincenzo Collura, Karim Tit, Laura Bussi, Eleonora Giunchiglia, Maxime Cordy
TL;DR
ABS tackles the challenge of enforcing formal constraints in autoregressive sequence generation by embedding a compiled DFA into a model-agnostic, inference-time beam search. The Ramp Push-Up mechanism adaptively biases decoding toward accepting DFA states, ensuring constraint satisfaction without retraining while preserving naturalness. The authors prove soundness and demonstrate that ABS achieves perfect constraint compliance across constrained image sequence classification, constrained text generation, and text infilling, while matching or surpassing baselines on standard quality metrics and improving efficiency. This approach broadens the applicability of constrained generation to any regular language (including LTL_f and regex) and offers practical benefits for high-stakes and safety-critical deployments.
Abstract
Sequence generation and prediction form a cornerstone of modern machine learning, with applications spanning natural language processing, program synthesis, and time-series forecasting. These tasks are typically modeled in an autoregressive fashion, where each token is generated conditional on the preceding ones, and beam search is commonly used to balance exploration and fluency during decoding. While deep learning models and Large Language Models (LLMs) excel at capturing statistical patterns in this setting, they remain ill-equipped to guarantee compliance with formal constraints. In this paper, we introduce ABS: a general and model-agnostic inference-time algorithm that guarantees compliance with any constraint that can be compiled into a Deterministic Finite Automaton (DFA), without requiring retraining. ABS leverages the DFA to guide a constrained variant of beam search: at each decoding step, transitions leading to violations are masked, while remaining paths are dynamically re-ranked according to both the model's probabilities and the automaton's acceptance structure. We formally prove that the resulting sequences are guaranteed to satisfy the given constraints, and we empirically demonstrate that ABS also improves output quality. We validate our approach on three distinct tasks: constrained image-stream classification, controlled text generation, and text infilling. In all settings, ABS achieves perfect constraint satisfaction, while outperforming or matching state-of-the-art baselines on standard quality metrics and efficiency.
