NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Earley-Driven Dynamic Pruning for Efficient Structured Decoding

Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni

Abstract

Large Language Models (LLMs) often struggle to adhere to strict structural constraints, such as JSON schemas or domain-specific languages. While constrained decoding via Context-Free Grammars (CFGs) ensures structural integrity, it introduces significant computational overhead and memory bloat. We present Formatron, an efficient decoding engine powered by ZapFormat, a novel dynamic pruning algorithm. By identifying and eliminating redundant parsing states in real-time, Formatron achieves up to a 2x speedup in token throughput while maintaining 100% structural compliance across various LLM architectures.

Introduction

As LLMs are increasingly integrated into automated workflows, the demand for structured output—data that conforms to a specific machine-readable format—has surged. Standard constrained decoding techniques utilize Earley parsers to enforce these constraints. However, these parsers are historically "hoardy," maintaining a vast number of internal states to track every possible valid completion of a sentence. As generation progresses, these states multiply, leading to excessive memory consumption and preventing efficient state caching. This "memory bloat" becomes a primary bottleneck in high-throughput production environments.

Methodology

The ZapFormat Algorithm

The core innovation of this work is ZapFormat, a dynamic pruning strategy designed to keep the parser's state set lean. ZapFormat introduces the concept of High-level Regular Rules (HRR)—segments of a grammar that function as simple patterns.

Traditional Earley parsers retain information about the beginning of a sequence long after it has become irrelevant to the remaining generation. ZapFormat utilizes a dependency graph and reachability analysis to identify "dead" states. Once an HRR is matched, the algorithm determines which intermediate states are no longer necessary for future token validation and prunes them in real-time. This "garbage collection" for parsing states ensures that only the essential frontier of the grammar is maintained.

The Formatron Engine

Formatron implements ZapFormat within a high-performance engine optimized for LLM inference. Key architectural features include:

  • Canonical State Caching: By pruning states down to their bare essentials, ZapFormat creates "canonical" state representations. This significantly increases the likelihood of cache hits, allowing the engine to reuse parsing logic across different queries.
  • Context-Independent Mask Cache: To avoid redundant calculations, the engine pre-computes token masks for common terminals (e.g., strings, integers, or specific keywords).
  • Rejection Prefix Optimization: The engine identifies impossible paths early in the process, stopping wasted computation on prefixes that can never result in a valid parse.

Experimental Evaluation

Setup and Datasets

Formatron was evaluated against state-of-the-art baselines, including XGrammar, outlines, and lm-format-enforcer. The researchers utilized a diverse set of tasks and datasets:

  • Geoquery: Converting natural language into functional query language (FunQL).
  • JSON Generation & Schema Validation: Testing both raw JSON structure and adherence to complex, nested schemas.
  • Synthetic Robustness Testing: Using five different LLMs (including GPT-4 and Gemini) to generate 125 prompt variations to ensure stability across different linguistic contexts.

Model Compatibility

The engine was tested across several popular open-source architectures, including Gemma-2-9B, Llama-3-8B, Mistral-7B, and Qwen2.5-7B, to demonstrate its generalizability.

Key Results

Performance and Throughput

Formatron achieved a 2x increase in token throughput compared to existing baselines. This speedup was consistent across different model sizes and architectures, proving that the bottleneck in constrained decoding was effectively addressed by the pruning mechanism.

Memory Efficiency

In tests with Llama-3 and Mistral, the pruning mechanism significantly reduced maximum memory usage. By preventing state explosion, Formatron allows for more concurrent requests and more efficient use of hardware resources. Importantly, this efficiency does not come at the cost of accuracy; the engine maintained 100% structural compliance and high precision across all benchmarks.

Discussion and Future Work

While Formatron represents a significant leap in decoding efficiency, certain challenges remain. The pre-computation of token masks, while faster than previous methods, still incurs an initial setup cost that scales with vocabulary size. Additionally, while the engine handles standard CFGs with ease, extremely deep or highly ambiguous grammars may still test the limits of current pruning strategies.

Future research will focus on tighter integration with LLM serving frameworks like vLLM or TGI. By embedding these optimizations directly into the inference stack, structured decoding can become a standard, low-overhead feature for all LLM applications.

Conclusion

Formatron demonstrates that the overhead of constrained decoding is not an inherent property of grammar enforcement, but rather a byproduct of inefficient state management. Through the ZapFormat pruning algorithm, we can achieve the reliability of formal grammars with the speed required for real-time applications, effectively bridging the gap between flexible LLM generation and rigid data requirements.

Summary updated

BibTeX
@inproceedings{sun2025earley,
  author = {Xintong Sun and Chi Wei and Minghao Tian and Shiwen Ni},
  title = {{Earley-Driven Dynamic Pruning for Efficient Structured Decoding}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=6hDNXCdTsE},
}
Figure