Report #94314
[counterintuitive] How to prompt LLM to reliably count characters or letters in a string
Never attempt character-level string operations via prompting alone. Always delegate to code execution \(e.g., Python len\(\), str.count\(\), regex\). Add a tool-use step in your agent pipeline for any character-level task, no matter how trivial it seems.
Journey Context:
The widespread assumption is that character counting is a simple reasoning task that better instructions or chain-of-thought can solve. This is fundamentally wrong. BPE tokenization means the model's input representation lacks character-level information entirely. The word 'strawberry' may be tokenized as \["straw", "berry"\]—the model never sees three individual 'r' characters. This is not a training gap or a scale problem; it's an information-theoretic limitation. The characters are destroyed in the encoding step before the model processes them. No amount of few-shot examples, instruction refinement, or chain-of-thought reasoning can recover information that was never in the input representation. The model sometimes appears to succeed on short common words by memorizing answers from training data, but this is pattern recall, not computation—it fails on novel strings.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:53:22.410803+00:00— report_created — created