Trie Automata Accelerate LLM Constrained Decoding for Structured Output

Xingzi Xu, Karim Bouyarmane· August 14, 2026 View original

Key takeaways

  • Trie automata significantly accelerate constrained decoding for LLMs.
  • They precompute token masks for efficient structured output generation.
  • Performance gains include 7X faster per-step computation and 29X higher batch throughput.
  • This method ensures 100% output validity for large finite sets.

Who benefits

Software DevelopmentData ScienceE-commerceFinancial ServicesHealthcare

Summary

This paper introduces the trie automaton, a specialized mechanism that significantly speeds up constrained decoding for Large Language Models (LLMs) when generating structured outputs from large finite sets. It achieves this by precomputing per-node token masks using Aho-Corasick multi-pattern matching, leading to substantial throughput improvements.

Large Language Models (LLMs) are increasingly required to produce structured outputs that adhere to predefined schemas, often involving selection from a vast finite set of valid strings. Current constrained decoding systems struggle with this "cardinality wall" as the number of valid values grows, leading to prohibitively slow performance. This research introduces the trie automaton, a novel mechanism specifically designed to address this challenge. The trie automaton leverages the inherent structure of finite sets, such as shared prefixes and bounded depth, by employing Aho-Corasick multi-pattern matching to precompute per-node token masks. This specialized approach results in a 7X faster per-step valid-token computation compared to existing general-purpose grammar compilation backends like XGrammar, and 2-6.5X faster compilation for larger sets. Crucially, these precomputed masks enable a stateless serving path that bypasses the guided decoding pipeline, leading to compounding advantages in batch serving. End-to-end vLLM throughput reached 219 requests/second with the trie automaton versus 7.5 requests/second with XGrammar at batch size 256, representing a 29X improvement. The trie maintains sub-100ms compilation for up to 10,000 values and offers a flat per-step cost regardless of set size, guaranteeing 100% output validity across various tokenizer families.

Why it matters

For professionals deploying LLMs in production environments that require precise, structured outputs (e.g., JSON, SQL, API calls), this innovation offers a critical performance boost, enabling higher throughput and lower latency while ensuring output validity.

How to implement this in your domain

  1. 1Evaluate current LLM deployment pipelines for bottlenecks in constrained decoding for structured outputs.
  2. 2Explore integrating trie automaton-based constrained decoding into existing LLM serving frameworks like vLLM.
  3. 3Benchmark the performance gains of trie automata against current grammar-based constrained decoding methods.
  4. 4Prioritize use cases where LLMs generate outputs from large, predefined finite sets (e.g., enum values, specific entity lists).
  5. 5Contribute to or adopt open-source implementations that incorporate trie automata for constrained decoding.

Original post by Xingzi Xu, Karim Bouyarmane

"arXiv:2608.12574v1 Announce Type: new Abstract: Large language models increasingly need to generate structured outputs that conform to predefined schemas, with one common constraint being selection from a finite set of valid strings. Current constrained decoding systems handle th…"

View on X

Originally posted by Xingzi Xu, Karim Bouyarmane on X · view source

Want to go deeper?

Turn these trends into skills with Learnijoy's hands-on AI & tech courses.

Explore courses

More in AI Engineering & DevTools