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

cjk-structured-llm-output-truncates-json-needs-2x-tokens is a skill for Claude Code from wan-huiyan/agent-traffic-control. It costs 227 tokens per session (1,321 once invoked), scanned A, original, MIT.

A guidance note about generating long Chinese, Japanese, or Korean JSON responses from language models. JSON is a structured text format that programs can parse.

In plain words
What is it for?
Use it when a long CJK response ends mid-JSON or produces a parsing error. It helps set a larger output budget and handle incomplete results.
Why use it?
These languages often use more model tokens than an equivalent English response, so a fixed output limit can cut the JSON off and make parsing fail.

Skill for Claude Code

Written for Claude Code: disable-model-invocation in frontmatter. Also seen: mentions Claude Code.

Part of the agent-traffic-control plugin — 118 skills shipped together

Good fit Use it when a long CJK response ends mid-JSON or produces a parsing error. It helps set a larger output budget and handle incomplete results.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/wan-huiyan/agent-traffic-control/cjk-structured-llm-output-truncates-json-needs-2x-tokens
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add wan-huiyan/agent-traffic-control --skill cjk-structured-llm-output-truncates-json-needs-2x-tokens
Clone the repo
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control

Made for: Claude Code.

Or install agent-traffic-control, the plugin that ships this one along with the rest of its 118 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cjk-structured-llm-output-truncates-json-needs-2x-tokens

README.md
[![agentmods](https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/cjk-structured-llm-output-truncates-json-needs-2x-tokens/github.svg)](https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/cjk-structured-llm-output-truncates-json-needs-2x-tokens)
Your own site
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/cjk-structured-llm-output-truncates-json-needs-2x-tokens"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/cjk-structured-llm-output-truncates-json-needs-2x-tokens/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for cjk-structured-llm-output-truncates-json-needs-2x-tokens

Your own site · 80×15
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/cjk-structured-llm-output-truncates-json-needs-2x-tokens"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/cjk-structured-llm-output-truncates-json-needs-2x-tokens.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 227 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,321 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00227 $0.01321
Opus 5.5 $0.00091 $0.00528
Sonnet 5.5 $0.00045 $0.00264
Haiku 4.5 $0.00023 $0.00132

Measured 3mo ago against content hash d7218f2a8f2c, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cjk-structured-llm-output-truncates-json-needs-2x-tokens scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/agent-traffic-control/skills/cjk-structured-llm-output-truncates-json-needs-2x-tokens/SKILL.md · 86 lines

How it starts

The opening of the file, as written. The whole thing — 86 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Long CJK structured output truncates JSON — budget ~2× tokens, and salvage the rest

Problem

You ask an OpenAI-compatible LLM for a long JSON report. In English it returns valid JSON. In Chinese (or Japanese/Korean) the identical request returns a string that starts with valid JSON but is cut off mid-object → json.loads fails, your regex \{.*\} grabs an unbalanced blob, and you get "no parseable JSON".

Why

  • CJK is token-dense. One Han character is often 1–2 BPE tokens; English averages ~0.25 tokens/char. The same report is ~1.5–2× more output tokens in Chinese. A max_tokens that comfortably fit the English report truncates the Chinese one.
  • Per-model output caps differ and some are low. Requesting max_tokens above a model's hard cap is either rejected (400 ... Range of max_tokens should be [1, 8192]) or silently clamped, then the long CJK report truncates. Observed: qwen-max hard-caps at 8192 (can't emit a full Chinese report); glm-4.6 / minimax ≈16K; qwen-plus / qwen3-235b / glm-5.2 / kimi / deepseek handle 24–32K. Reasoning models also spend tokens on reasoning_content before the JSON, compounding it.

Fix

  1. Budget ~2× the English max_tokens for CJK (e.g. 16000–32000 for a full report), per model, up to its cap.
  2. Probe the cap if a 400 appears — binary-search max_tokens (a tiny call that 400s vs 200s reveals the ceiling). For reasoning models, leave headroom for reasoning_content.
  3. Salvage truncated JSON instead of failing — close the object after the last complete top-level section. Walk the string tracking brace/bracket depth and string/escape state; record the index each time depth returns to 1 (a top-level value just closed); cut there and append }:
    def salvage(c):
        s = c[c.find("{"):]; depth=0; instr=False; esc=False; cut=None
        for i,ch in enumerate(s):
            if esc: esc=False; continue
            if instr:
                if ch=="\\": esc=True
                elif ch=='"': instr=False
                continue
            if ch=='"': instr=True
            elif ch in "{[": depth+=1
            elif ch in "}]":
                depth-=1
                if depth==1: cut=i+1
        if cut:
            try:
                d=json.loads(s[:cut].rstrip().rstrip(",")+"}")
                if isinstance(d,dict) and len(d)>=MIN_SECTIONS: return d
            except Exception: pass
        return None
    
    Truncation then degrades gracefully — the report keeps its complete sections, and the missing tail shows up as lower "comprehensiveness" in scoring rather than a hard failure.
  4. Also strip reasoning prefixes before parsing: some models inline chain-of-thought as <think>…</think> before the JSON (MiniMax-M3) — re.sub(r"(?is)^.*?</think>","",c) first.

Read the full file on GitHub · 86 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 86 lines · 227 tokens per session scan A d7218f2a8f2c

Subscribe to this mod's changes

cjk-structured-llm-output-truncates-json-needs-2x-tokens is a skill published in the GitHub repository wan-huiyan/agent-traffic-control (3 stars, last pushed 3d ago), licensed MIT. It adds 227 tokens to every session and 1,321 once invoked, about $0.0009 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

cjk-structured-llm-output-truncates-json-needs-2x-tokens compared with skills from other repositories

cjk-structured-llm-output-truncates-json-needs-2x-tokens next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
cjk-structured-llm-output-truncates-json-needs-2x-tokenswan-huiyan/agent-traffic-controlSkill33d agoMITA227Claude Code
cloudflare-workers-aisecondsky/claude-skillsSkill2578d agoMITA39Claude Code
ask-claudethoughtbot/rails-consultantSkill399d agoMITA97Claude Code
rag-vs-finetune-decisionVandanaAjayDubey111/great-pmSkill32mo agoMITA109Claude Code
ai-use-case-scopingVandanaAjayDubey111/great-pmSkill32mo agoMITA85Claude Code
prompt-mininidhinjs/prompt-miniSkill318mo agoMITA37Claude Code
fable-promptingjjilli/fable-flowSkill24mo agoMITA89Claude Code