Skip to content

Stay Within Your Bounds: Distance-Guided Decoding for Guaranteed Context-Free Grammar Compliance

Aug 2026 · 1 citation · 28 references
Computer Science

TL;DR

This work proposes a lookahead-guided decoding framework for context-free grammars based on pushdown automata based on bounded pushdown summaries with reachability labels and upper-bound distances to acceptance.

Abstract

Grammar-constrained decoding helps large language models produce syntactically valid structured outputs, such as code, JSON, and SQL. For context-free grammars, many practical decoders enforce local prefix feasibility: each token must keep the current prefix extendable to some valid completion. Yet, under tokenizer-grammar mismatch and finite token budgets, feasible prefixes may still fail to reach acceptance. We propose a lookahead-guided decoding framework for context-free grammars based on pushdown automata. Offline, we compute bounded pushdown summaries with reachability labels and upper-bound distances to acceptance. Online, these estimates guide horizon-aware pruning and beam search. The resulting decoder is syntactically sound: every output is accepted by the target grammar. Experiments on JSON, SQL, and Linear Temporal Logic (LTL) show both consistent syntactic validity and improved completion quality over existing baselines.

View source

Similar papers

Open access Aug 2026

Efficient Grammar-Constrained Decoding via Parser Stack Classification

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.

Yong-Ming Li, Yihong Dong, Jia Li et al. · 0 citations
Preprint Aug 2026

Learning Context-Free Grammars for Grammar-Constrained Decoding via Declarative Agentic Programming with Guarantees

This work defines an agent, called Autogrammar, that automatically learns context-free grammars from documentation and execution data, formalized as a Kripke structure whose nondeterministic choices are resolved by a language model, enabling declarative control of agent behavior via linear temporal logic constraints.

K. Cheang, G. Hulette, Rahul Kumar et al. · 0 citations
Preprint Aug 2026

Trie Automata for Constrained Decoding over Large Finite Sets

The trie automaton is introduced, a specialized mechanism that exploits finite-set structure via Aho-Corasick multi-pattern matching to precompute per-node token masks, and achieves 7X faster per-step valid-token computation compared to XGrammar and 2.5X faster compilation at K>= 300.

Xingzi Xu, Karim Bouyarmane · 0 citations
#natural language process... Preprint Aug 2026

The Parser Already Knows: Lightweight Bias Correction in Constrained Decoding

SHIM is introduced, a lightweight, offline-trained correction of the LM's next-token probabilities, conditioned on this syntactic and lexical state together with candidate next tokens, which substantially narrows the gap to the LM's grammar-conditioned distribution compared to masking and online sampling, while running...

Işıl Özgü, Yaoxuan Wu, Guy Van den Broeck et al. · 0 citations
Conference Open access Sep 2026

Grammar-State Aware Beam Search for Enhancing Structural Diversity in LLM Generation

GSA-Beam improves explicit state coverage and final structural diversity while preserving schema validity while preserving schema validity; across several LLM backbones, it reduces reference latency by 22.5% on average compared with standard constrained beam search.

Han-Tao Hua, Ji-Ming Su, Yi-Ping Yao et al. · 0 citations

Related blog posts

MIT News · Artificial Intelligence Sep 29, 2026

Who we become when we talk to machines

Professor Sherry Turkle’s new book, “Artificial Intimacy,” offers a withering critique of chatbots and the antisocial dynamics she believes they encourage.

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