cjk-structured-llm-output-truncates-json-needs-2x-tokens

Diagnose and fix truncated JSON from long CJK LLM outputs by budgeting tokens and salvaging partial objects.

3|Updated May 8, 2026
Ready to run
npx skills add https://github.com/wan-huiyan/agent-traffic-control --skill cjk-structured-llm-output-truncates-json-needs-2x-tokens-wan-huiyan
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: cjk-structured-llm-output-truncates-json-needs-2x-tokens
Source: https://github.com/wan-huiyan/agent-traffic-control/tree/main/plugins/agent-traffic-control/skills/cjk-structured-llm-output-truncates-json-needs-2x-tokens
Command: npx skills add https://github.com/wan-huiyan/agent-traffic-control --skill cjk-structured-llm-output-truncates-json-needs-2x-tokens-wan-huiyan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Long Chinese, Japanese, or Korean structured output from an LLM chat API truncates mid-JSON and breaks parsing with errors like "Expecting ',' delimiter" or JSONDecodeError, even though the identical English prompt worked. The cause is that CJK text is token-dense (roughly 1-2 tokens per character versus about 0.25 for English), so a report that fit your max_tokens in English overflows it in Chinese, and some models additionally hard-cap output below what you request. ## Core Features & Use Cases - Token Budgeting Rule: Budget roughly 2x the English max_tokens for CJK output (e.g. 16000-32000 for a full report), per model, up to its hard cap. - Per-Model Cap Probing: Binary-search max_tokens when a 400 error appears to discover a model's output ceiling, and leave headroom for reasoning_content on reasoning models. - Truncated JSON Salvage: A brace/bracket depth-tracking snippet closes the object after the last complete top-level section, so a truncated report degrades gracefully instead of failing outright. - Use Case: In a multi-model Chinese report-generation bake-off, qwen-max hard-capped at 8192 tokens and truncated every long rollout, while bumping other models to 16-32K tokens fixed them; the salvage routine turned remaining truncations into judgeable partial reports. ## Quick Start Ask the assistant to diagnose why my Chinese JSON report generation truncates mid-object and apply the 2x token budget plus the brace-depth salvage fix.

Frequently Asked Questions about cjk-structured-llm-output-truncates-json-needs-2x-tokens

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my LLM JSON output truncate in Chinese but work in English?▼

CJK text is token-dense: one Han character is often 1-2 BPE tokens versus about 0.25 tokens per English character. The same report needs roughly 1.5-2x more output tokens in Chinese, so a max_tokens value that fit the English version truncates the Chinese one mid-object.

How do I fix JSONDecodeError on long CJK LLM responses?▼

Raise max_tokens to about 2x your English budget (typically 16000-32000 for a full report), staying under the model's hard cap. If truncation persists, salvage the response by closing the JSON after the last complete top-level section using brace-depth tracking.

Which LLM models have low output token caps for long reports?▼

qwen-max hard-caps output at 8192 tokens and cannot emit a full long Chinese report. glm-4.6 and minimax reach about 16K, while qwen-plus, qwen3-235b, glm-5.2, kimi, and deepseek handle 24-32K output tokens.

How can I recover partial data from truncated JSON output?▼

Walk the string tracking brace and bracket depth plus string and escape state, recording the index each time depth returns to 1. Cut there, append a closing brace, and parse; the result keeps all complete top-level sections instead of failing entirely.

Why does my model return a 400 error when I raise max_tokens?▼

The requested max_tokens exceeds the model's hard output cap, producing an error like "Range of max_tokens should be [1, 8192]". Binary-search max_tokens with small probe calls to find the ceiling, and leave headroom for reasoning_content on reasoning models.

How do I handle think tags before JSON in LLM responses?▼

Some models inline chain-of-thought as <think>...</think> before the JSON payload. Strip it with a regex substitution removing everything up to the closing think tag before attempting to parse the response.