TruncProof: A Guardrail for LLM-based JSON Generation under Token-Length Constraints

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Kato, Yoshio, Tarashima, Shuhei
Format: Preprint
Published: 2026
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866909039492857856
author Kato, Yoshio
Tarashima, Shuhei
author_facet Kato, Yoshio
Tarashima, Shuhei
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2605_13076
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle TruncProof: A Guardrail for LLM-based JSON Generation under Token-Length Constraints
Kato, Yoshio
Tarashima, Shuhei
Computation and Language
Formal Languages and Automata Theory
Software Engineering
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.
title TruncProof: A Guardrail for LLM-based JSON Generation under Token-Length Constraints
topic Computation and Language
Formal Languages and Automata Theory
Software Engineering
url https://arxiv.org/abs/2605.13076