PulseAugur
EN
LIVE 10:28:21

Python JSON default inflates Claude token costs for non-ASCII text

A developer discovered that using Python's default `json.dumps` with `ensure_ascii=True` significantly inflated token counts when sending non-ASCII characters, such as Korean Hangul, to Anthropic's Claude. This default setting converts each non-ASCII character into a multi-character escape sequence (e.g., `\uXXXX`), which the LLM tokenizer then interprets as multiple tokens instead of a single character. The issue was identified by comparing token counts for English and Korean voice sessions, revealing that the Korean prompts were over three times larger. The fix involves setting `ensure_ascii=False` in `json.dumps` and ensuring that the resulting JSON string is correctly handled before being passed to the LLM. AI

IMPACT Developers should set `ensure_ascii=False` in Python's `json.dumps` to avoid inflated token costs when sending non-ASCII text to LLMs.

RANK_REASON Developer identifies a bug in a common programming tool (Python's json.dumps) that impacts LLM tokenization costs.

Read on dev.to — LLM tag →

AI-generated summary · Google Gemini · from 1 sources. How we write summaries →

Python JSON default inflates Claude token costs for non-ASCII text

COVERAGE [1]

  1. dev.to — LLM tag TIER_1 Français(FR) · jidonglab ·

    Python json.dumps ensure_ascii Made My Claude Prompts 2.3x Bigger

    <p>A 20-minute Korean voice session should cost about the same to score as a 20-minute English one. Mine cost more than twice as much, and for three months I assumed that was just "how Korean tokenizes."</p> <p>It wasn't. It was one default argument: <code>json.dumps</code> with …