Lune

ICML2025Top-tier venue

Flexible and Efficient Grammar-Constrained Decoding

Kanghee Park, Timothy Zhou, Loris D'Antoni

Abstract

Large Language Models (LLMs) are often asked to generate structured outputs that obey precise syntactic rules, such as code snippets or formatted data. Grammar-constrained decoding (GCD) can guarantee that LLM outputs matches such rules by masking out tokens that will provably lead to outputs that do not belong to a specified contextfree grammar (CFG). To guarantee soundness, GCD algorithms have to compute how a given LLM subword tokenizer can "align" with the tokens used by a given context-free grammar and compute token masks based on this information. Doing so efficiently is challenging and existing GCD algorithms require tens of minutes to preprocess common grammars. We present a new GCD algorithm together with an implementation that offers 17.71x faster offline preprocessing than existing approaches while preserving state-of-theart efficiency in online mask computation.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

14 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Mitigating Bias in Locally Constrained Decoding via Tractable Proposals cites Grammar-Aligned Decoding
  • Mitigating Bias in Locally Constrained Decoding via Tractable Proposals cites Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective
  • CRANE: Reasoning with constrained LLM generation cites Guiding LLMs The Right Way: Fast, Non-Invasive Constrained Generation
  • CRANE: Reasoning with constrained LLM generation cites Grammar-Aligned Decoding
  • Guiding LLMs The Right Way: Fast, Non-Invasive Constrained Generation cites Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning
  • Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning cites Grammar Prompting for Domain-Specific Language Generation with Large Language Models
  • Grammar-Aligned Decoding cites Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning
  • Grammar-Aligned Decoding cites Grammar Prompting for Domain-Specific Language Generation with Large Language Models
  • Constrained Adaptive Rejection Sampling cites Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning
  • Constrained Adaptive Rejection Sampling cites Grammar-Aligned Decoding
  • Constrained Adaptive Rejection Sampling cites Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective
  • Constrained Adaptive Rejection Sampling cites Grammar Prompting for Domain-Specific Language Generation with Large Language Models
  • Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective cites Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning
  • Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective cites Grammar-Aligned Decoding
  • Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective cites Grammar Prompting for Domain-Specific Language Generation with Large Language Models
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers14

  1. 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
  2. The Hidden Cost of Structured Generation in LLMs: Draft-Conditioned Constrained DecodingAvinash Reddy, Thayne Walker, Jaime Ide, Amrit Singh BediICML 2026 · 6 citations
  3. Mitigating Bias in Locally Constrained Decoding via Tractable ProposalsMeihua Dang, Linxin Song, Honghua Zhang, Jieyu Zhao et al.ICML 2026 · 4 citations
  4. ToolPRM: Fine-Grained Inference Scaling of Structured Outputs for Function CallingJianghao Lin, Yuanyuan Shi, Xin Peng, Renjie Ding et al.ACL 2026 · 3 citations
  5. Constrained Adaptive Rejection SamplingPaweł Parys, Sairam Vaidya, Taylor Berg-Kirkpatrick, Loris D'AntoniICML 2026 · 3 citations

Builds on5

  1. Grammar Prompting for Domain-Specific Language Generation with Large Language ModelsBailin Wang, Zi Wang, Xuezhi Wang, Yuan Cao et al.NeurIPS 2023 · 138 citations
  2. Guiding LLMs The Right Way: Fast, Non-Invasive Constrained GenerationLuca Beurer-Kellner, Marc Fischer, Martin T. VechevICML 2024 · 93 citations
  3. Grammar-Aligned DecodingKanghee Park, Jiayu Wang, Taylor Berg-Kirkpatrick, Nadia Polikarpova et al.NeurIPS 2024 · 73 citations
  4. Grammar-Constrained Decoding for Structured NLP Tasks without FinetuningSaibo Geng, Martin Josifoski, Maxime Peyrard, Robert WestEMNLP 2023 · 33 citations
  5. CRANE: Reasoning with constrained LLM generationDebangshu Banerjee, Tarun Suresh, Shubham Ugare, Sasa Misailovic et al.ICML 2025

Related papers

  1. Efficient Grammar-Constrained Decoding via Parser Stack ClassificationYongmin Li, Yihong Dong, Jia Li, Ge LiISSTA 2026
  2. Gram2Token: Enabling Run-time GPU-Native Grammar-Constrained Decoding for LLMsHantao Hua, Jiming Su, hao tang, Yiping Yao et al.ICML 2026
  3. Constrained Decoding of Diffusion LLMs with Context-Free GrammarsNiels Mündler, Jasper Dekoninck, Martin VechevICLR 2026 · 18 citations
  4. Earley-Driven Dynamic Pruning for Efficient Structured DecodingXintong Sun, Chi Wei, Minghao Tian, Shiwen NiICML 2025
  5. ChopChop: A Programmable Framework for Semantically Constraining the Output of Language ModelsShaan Nagy, Timothy Zhou, Nadia Polikarpova, Loris D'AntoniPOPL 2026 · 1 citation
Dusk over the sea between two cliffs drawn in fine vertical lines