Abstract:The LLM-based generation of machine-readable outputs such as JSON has attracted significant attention for integration with external systems. However, existing approaches cannot strictly enforce the maximum number of tokens to be generated, leading to infinite generation or truncated outputs that cause a system malfunction. To address this limitation, we propose TruncProof, a novel grammar-constrained generation method that enables LLMs to produce grammatically valid JSONs while adhering to a predefined token limit. By leveraging the properties of LL(1) parsers, TruncProof efficiently approximates the minimum number of tokens required to complete a grammatically valid output at each decoding step. Experiments on the Text-to-JSON instruction tasks demonstrate that TruncProof successfully generates syntactically correct outputs even under strict token constraints. Furthermore, we show that TruncProof can be effectively combined with advanced decoding strategies, resulting in outputs that are not only grammatically valid but also semantically accurate.
| Comments: | Main paper (8 pages). Accepted at the International Joint Conference on Neural Networks (IJCNN 2026) |
| Subjects: | Computation and Language (cs.CL); Formal Languages and Automata Theory (cs.FL); Software Engineering (cs.SE) |
| Cite as: | arXiv:2605.13076 [cs.CL] |
| (or arXiv:2605.13076v1 [cs.CL] for this version) | |
| https://doi.org/10.48550/arXiv.2605.13076 arXiv-issued DOI via DataCite (pending registration) |
Submission history
From: Yoshio Kato [view email]
[v1]
Wed, 13 May 2026 06:49:08 UTC (458 KB)
