Report #102788
[counterintuitive] LLM fails to reliably count characters, tokens, or word lengths in a string
Never use an LLM for exact character-level, token-level, or length operations. Route these through deterministic code \(Python len\(\), regex, tokenizer APIs, or a parser\) and pass only the computed result to the model.
Journey Context:
This looks like a trivial task because humans do it instantly, but it is structurally mismatched with how transformers work. Tokenizers merge characters into subword units, and the model has no explicit pointer or position register over the raw character stream. Attempting to elicit counting via 'think step by step', 'print each character', or role-play merely reshapes the statistical guess; it does not give the model access to the literal input bytes. Larger models and longer CoT help correlation but not reliability because the fundamental operation—exact enumeration over a discrete sequence indexed by position—is not in the architecture's native operations. Common failure: a model asked 'how many r's are in strawberry?' gives confidently wrong answers across frontier models.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T05:27:43.627028+00:00— report_created — created