Constrained Adaptive Rejection Sampling
Paweł Parys, Sairam Vaidya, Taylor Berg-Kirkpatrick, Loris D'Antoni
Abstract
Language Models (LMs) are increasingly used in applications where generated outputs must satisfy strict semantic or syntactic constraints. Existing approaches to constrained generation fall along a spectrum: greedy constrained decoding methods enforce validity during decoding but distort the LM’s distribution, while rejection sampling (RS) preserves fidelity but wastes computation by discarding invalid outputs. Both extremes are problematic in domains such as program fuzzing, where both validity and diversity of samples are essential. We present Constrained Adaptive Rejection Sampling (CARS), an approach that strictly improves the sample-efficiency of RS without distributional distortion. CARS begins with unconstrained LM sampling and adaptively rules out constraint-violating continuations by recording them in a trie and subtracting their probability mass from future draws. This adaptive pruning ensures that prefixes proven invalid are never revisited, acceptance rates improve monotonically, and the resulting samples exactly follow the constrained distribution. In experiments on a variety of domains---e.g., program fuzzing and molecular generation---CARS consistently achieves higher efficiency---measured in the number of LM forward passes per valid sample---while also producing stronger sample diversity than both Greedy Constrained Decoding (GCD) and methods that approximate the LM's distribution.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext d2198634-ecd8-493c-92f6-540d0e1af78fCited by top-tier papers2
- Continuous Diffusion Models Can Obey Formal SyntaxJinwoo Kim, Taylor Berg-Kirkpatrick, Loris D'AntoniICML 2026
- Lookahead-Then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free GrammarsYitong Zhang, Yongmin Li, Yuetong Liu, Jia Li et al.ISSTA 2026
Builds on17
- Coverage-based Greybox Fuzzing as Markov ChainMarcel Böhme, Van-Thuan Pham, Abhik RoychoudhuryCCS 2016 · 1,026 citations
- Hierarchical Generation of Molecular Graphs using Structural MotifsWengong Jin, Regina Barzilay, Tommi S. JaakkolaICML 2020 · 356 citations
- COLD Decoding: Energy-based Constrained Text Generation with Langevin DynamicsLianhui Qin, Sean Welleck, Daniel Khashabi, Yejin ChoiNeurIPS 2022 · 217 citations
- Grammar Prompting for Domain-Specific Language Generation with Large Language ModelsBailin Wang, Zi Wang, Xuezhi Wang, Yuan Cao et al.NeurIPS 2023 · 138 citations
- Prompting Is Programming: A Query Language for Large Language ModelsLuca Beurer-Kellner, Marc Fischer, Martin T. VechevPLDI 2023 · 114 citations
Related papers
- Constrained Sampling for Language Models Should Be Easy: An MCMC PerspectiveEmmanuel Anaya Gonzalez, Sairam Vaidya, Kanghee Park, Ruyi Ji et al.NeurIPS 2025 · 15 citations
- Grammar-Aligned DecodingKanghee Park, Jiayu Wang, Taylor Berg-Kirkpatrick, Nadia Polikarpova et al.NeurIPS 2024 · 73 citations
- Approximately Aligned DecodingDaniel Melcer, Sujan Kumar Gonugondla, Pramuditha Perera, Haifeng Qian et al.NeurIPS 2025 · 3 citations
- Controllable Generation via Locally Constrained ResamplingKareem Ahmed, Kai-Wei Chang, Guy Van den BroeckICLR 2025
- Guaranteed Generation from Large Language ModelsMinbeom Kim, Thibaut Thonet, Jos Rozen, Hwaran Lee et al.ICLR 2025
