Report #84765
[counterintuitive] Why can't the LLM count characters in a string or count words reliably, no matter how I prompt it?
Never ask an LLM to directly count characters, words, or tokens. Delegate all counting operations to external tool use — have the model write and execute a Python one-liner or shell command. If you must estimate, ask the model to generate a counting script, not to count directly.
Journey Context:
Developers assume character counting is trivial and try increasingly elaborate prompts to make it work. The real issue is BPE tokenization: the model's input representation doesn't contain characters — it contains variable-length subword tokens. 'hello' might be a single token \[31373\], but 'helloworld' might be two tokens \[31373, 2896\]. The model literally cannot count characters because it never sees them; it sees opaque integer token IDs. No prompt, no matter how clever, can recover information that was destroyed by the tokenizer before the model ever processes it. This also affects exact string matching, substring operations, and whitespace/indentation counting. The fix isn't a better prompt; it's a different tool for the job.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:52:05.790460+00:00— report_created — created