Decode-Time Grammars: Constrained LLM Generation over a Refinement Order of Grammar Fragments
Not on the map. Why?
Abstract (arXiv)
Large language models now write a growing share of the world's code, increasingly inside agents and serving systems that compile, execute, or dispatch generated code without line-by-line review. This works well for mainstream languages but remains brittle for low-resource programming surfaces such as domain-specific languages, custom library APIs, and command-line tools. Even under grammar-constrained decoding, a model can still produce references invalid in the current environment: a buffer never declared, a column absent from the schema, a function the library does not provide, or an unsupported CLI option. This paper introduces decode-time grammars: grammar fragments instantiated during generation from a runtime environment Gamma. A region-specific policy selects a fragment for each hole, and a tightening operator replaces open reference positions with Gamma-typed slots whose candidates are exactly the names, fields, APIs, or options available at that point. Newly generated declarations enter Gamma before later regions are decoded, so the constraining grammar can depend on the prefix already generated. This ensures not only grammatical correctness but also semantic correctness, by preventing references to undefined symbols. We formalize grammar fragments as environment-indexed grammars ordered by refinement, prove No-Ghost soundness for Gamma-slotted fragments, show that refinement preserves this support-set guarantee, and characterize the boundary of mask-enforceable properties. We implement the approach in gproj with offline grammar induction and online policy resolution. Across TileLang, SQL, and P4, with models from 0.6B to 236B parameters, gproj eliminates ghost references by construction at moderate overhead over standard constrained decoding.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 32 of its 68 references that are in the map. First posted on arXiv 20 Jul 2026.
Builds on
32 of 68 references.
References · 32
- 2017Attention Is All You Needcited by 60,361
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2015Distilling the Knowledge in a Neural Networkcited by 10,324
- 2022ReAct: Synergizing Reasoning and Acting in Language Modelscited by 8,695
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2023Efficient Memory Management for Large Language Model Serving with PagedAttentioncited by 5,944
- 2023Toolformer: Language Models Can Teach Themselves to Use Toolscited by 4,182
- 2023SWE-bench: Can Language Models Resolve Real-World GitHub Issues?cited by 3,373
- 2023GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpointscited by 1,346
- 2018Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Taskcited by 1,139
- 2026DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligencecited by 1,040
- 2021PICARD: Parsing Incrementally for Constrained Auto-Regressive Decoding from Language Modelscited by 411
20 more
- 2025KernelBench: Can LLMs Write Efficient GPU Kernels?cited by 225
- 2023Grammar-Constrained Decoding for Structured NLP Tasks without Finetuningcited by 197
- 2023Is Self-Repair a Silver Bullet for Code Generation?cited by 197
- 2024SynCode: LLM Generation with Grammar Augmentationcited by 69
- 2024We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMscited by 65
- 2022When Language Model Meets Private Librarycited by 54
- 2023Knowledge Transfer from High-Resource to Low-Resource Programming Languages for Code LLMscited by 45
- 2025TileLang: A Composable Tiled Programming Model for AI Systemscited by 43
- 2025Type-Constrained Code Generation with Language Modelscited by 35
- 2024CodeHalu: Investigating Code Hallucinations in LLMs via Execution-based Verificationcited by 34
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtrackingcited by 29
- 2022babble: Learning Better Abstractions with E-Graphs and Anti-Unificationcited by 23
- 2013Programming Protocol-Independent Packet Processorscited by 21
- 2025ChopChop: a Programmable Framework for Semantically Constraining the Output of Language Modelscited by 15
- 2016Hazelnut: A Bidirectionally Typed Structure Editor Calculuscited by 8
- 2026Mitigating Bias in Locally Constrained Decoding via Tractable Proposalscited by 8
- 2025Correctness-Guaranteed Code Generation via Constrained Decodingcited by 7
- 2021Learning Highly Recursive Input Grammarscited by 4
- 2025HyGenar: An LLM-Driven Hybrid Genetic Algorithm for Few-Shot Grammar Generationcited by 2
- 2023Languages with Decidable Learning: A Meta-theoremcited by 1
Built on by
Not cited yet.