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.
AI-generated summary · Google Gemini · from 1 sources. How we write summaries →