Skip to content
Open access

Efficient Grammar-Constrained Decoding via Parser Stack Classification

Aug 2026 · Proceedings of the ACM on Software Engineering · Vol 3, pp. 1856 - 1880 · 0 citations · 39 references
Computer Science

TL;DR

The proposed PSC, a novel grammar-constrained decoding method, can compute the complete vocabulary mask by checking the parser stack exactly once per decoding step, with time complexity independent of the vocabulary size.

Abstract

LLMs are widely used to generate structured output like source code or JSON. Grammar-constrained decoding (GCD) can guarantee the syntactic validity of the generated output, by masking out tokens that violate rules specified by a context-free grammar. However, the online computational overhead of existing GCD methods, with latency typically scaling linearly with vocabulary size, limits the throughput of LLMs, especially for models with large vocabularies. To address this issue, we propose PSC, a novel grammar-constrained decoding method. By combining acceptance conditions of all vocabulary tokens into a single classifier of the parser stack during preprocessing, PSC can compute the complete vocabulary mask by checking the parser stack exactly once per decoding step, with time complexity independent of the vocabulary size. Experiments show that PSC computes masks up to 700× faster than baselines on complex programming language grammars, and up to 30× faster for schema-conformant JSON; end-to-end LLM throughput with PSC approaches that of unconstrained decoding. We analyze the preprocessing overhead for preprocessing providers and decoding users, and provide a break-even point analysis to help users decide whether to do preprocessing by themselves.

Read PDF

Similar papers

Book Open access Oct 2026

SwiftGram: Dynamic Lexical Forking for Precise and Efficient Grammar-Constrained Decoding

Large Language Models (LLMs) must strictly adhere to grammatical constraints for reliable structured generation in agentic workflows, code synthesis, and domain-specific language (DSL) generation. Grammar-Constrained Decoding (GCD) enforces this by masking out tokens incompatible with the target grammar at each decodin...

Shu-Yi Ling, Liang-Yi Kang, Jie Liu et al. · 0 citations
Book Open access Oct 2026

Reliable Generation of Feature Models in the Universal Variability Language using Constrained LLMs

Modern software systems are increasingly variant-rich, and feature models capture this variability formally. The Universal Variability Language (UVL) has emerged as a community-driven standard for expressing such models, but creating and maintaining UVL artifacts remains a manual, expert-driven task. Large Language Mod...

Johannes Stümpfle, Fethiye Tunç, N. Jazdi et al. · 0 citations
Preprint Sep 2026

Where the LLM Ends and Reliable Decisions Begin

The ANVIL compiler architecture is proposed, where ANVIL performs exceptionally well on leading benchmarks by using language models purely where they are effective, rather than as a catch-all tool.

Priyadarshan Patil, A. Basu, Vikas Reddy et al. · 0 citations
#artificial intelligence Book Open access Sep 2026

Semantic Prefix Oracles for LLM Decoding: Contracts and Differential Validation

Constrained decoding can enforce regular or context-free output formats, but many program-generation failures are semantic: scope, typing, and declaration effects depend on context. We present semantic grammar specifications, a declarative formalism that attaches such constraints to a context-free surface and executes...

Paul Kronlund-Drouault · 0 citations
#natural language process... Preprint Oct 2026

Structural Automata for Neural Semantic Parsing

Neural semantic parsers generate meaning representations token by token, yet well-formedness depends on references, scope, and graph relations that unfold during generation. Constrained decoding prevents locally invalid tokens but does not guarantee that a valid prefix can be completed within a fixed output-length limi...

Xiao Zhang · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.