Tractable Hierarchical Control of Autoregressive Language Models
Scribner, Max, Vergari, Antonio, Belle, Vaishak
–arXiv.org Artificial Intelligence
The output of large language models (LLMs) often needs to be parsed and converted into a structured form. In code generation [Jiang et al., 2026], data generation [Li et al., 2024], and structured natural language processing tasks [Geng et al., 2023], large language models must generate sequences which satisfy a predetermined formal language to be processed for downstream tasks. Many of these languages are designed to be LR(k) languages, i.e., languages which can be parsed using a shiftreduce parser [Aho et al., 2006]. The class of automata that classify LR(k) languages is deterministic pushdown automata (DPDAs) [Knuth, 1965]. For this reason, improving the autoregressive generation of text that can be guaranteed to satisfy an arbitrary DPDA is important to the future of using the output of these models in formal systems. Even when prompted to satisfy simple hierarchical constraints, LLMs can fail, especially as the constraints stray out of their training distribution. Across four open LLMs (Figure 1), we found the models consistently failed to generate text satisfying a simple context-free grammar constraint, generating a short well-nested sequence of square brackets and angle brackets, called a Dyck-2 language (discussed in Ebrahimi et al. [2020]). We found that as the set of parentheses changes from the more canonical ()[] set to less attested parentheses in the literature on Dyck languages such as <> and {}, all models perform worse at generating well-typed and well-nested sequences. Despite the canonical Dyck-2 language showing up in these models' corpora, they fail to generate sequences satisfying the non-canonical but conceptually equivalent constraint requested, as illustrated 1
arXiv.org Artificial Intelligence
Jul-24-2026