AI
New Method Ensures Diffusion LLMs Follow Formal Language Rules
Researchers introduce the first constrained decoding technique for diffusion language models, enabling them to generate syntactically correct code and structured data.
A research team has developed a novel approach to constrained decoding for diffusion-based large language models, addressing a critical gap in generative AI reliability. The method ensures that model outputs strictly conform to formal languages—a requirement for tasks like code generation and data extraction where syntactic correctness is non-negotiable.
The Problem with Diffusion LLMs#
Diffusion language models represent an emerging alternative to traditional transformer-based LLMs. However, their probabilistic nature means they don't inherently guarantee that outputs will follow syntactic rules or formal specifications. This is particularly problematic for practical applications such as C++ code completion or JSON output validation, where any deviation from the formal structure can break downstream systems. Prior constrained decoding methods exist for conventional LLMs but cannot be applied to diffusion models.
How the Solution Works#
The researchers frame the problem as an additive infilling task—determining whether a partial output can be completed to form a valid word in the target language. This formulation also naturally extends to multi-region infilling scenarios previously unaddressed by existing methods. The team then reduces this challenge to deciding whether the intersection of the target language and a regular language is empty, and presents an efficient algorithm tailored for context-free grammars.
Empirical Results#
Testing across multiple applications demonstrated strong performance: the approach achieves near-perfect syntactic correctness on tasks like C++ code infilling and structured data extraction in JSON format. Notably, the method consistently preserves or even improves functional correctness—the semantic correctness of the generated content—while maintaining practical computational efficiency through targeted optimizations.
The work represents the first constrained decoding framework specifically designed for the diffusion LLM paradigm, filling a significant gap in making these models viable for formally structured output generation.

