Prompt engineering

Why AI can't count the letters in a word — it can't see them

Illustration: a word built from a few large tiles, a magnifier unable to split a tile into letters

Ask a model how many r's there are in "strawberry". There's a decent chance you'll get the wrong number — confidently, with an explanation attached.

A minute later that same model will write you a working script and untangle an unfamiliar error. It looks like mockery: it can do the hard thing and not the easy one.

It's actually perfectly logical. This isn't a gap in knowledge, it's a direct consequence of how the thing is built — and once you know the cause, one sentence fixes it.

Cause 1: the model physically cannot see letters

The thing to understand first: text doesn't reach the model as letters. It's chopped up beforehand into tokens — chunks of several characters. "Strawberry" arrives not as ten letters but as two or three glued-together fragments.

Imagine being shown a word as a single pictogram. You know what it means, you know how it sounds, you can use it in a sentence. But you can't count the strokes inside it — for you, they aren't there.

That's exactly the model's position. About "strawberry" it knows everything: what it is, what it tastes like, how it differs from a raspberry. The letters inside a chunk it cannot tell apart — the tokenizer saw them on the way in, and they never made it any further.

It's worse outside English, by the way. Other alphabets get sliced finer and less gracefully, chunk boundaries land in arbitrary places, and a word crumbles into fragments with no relationship to its letters at all.

How to check. Ask for the same word with separators: s-t-r-a-w-b-e-r-r-y. Now every letter is its own chunk, and the answer usually turns correct. If that works when the plain question doesn't, you've found your cause.

How to fix. Have it count from the spelled-out version: "first write the word out letter by letter with hyphens, then count."

Cause 2: counting is executing, not recalling

Even once the letters are visible, a second problem remains, and it runs deeper.

A language model doesn't execute algorithms. It picks the next chunk of text that looks plausible after the previous one. It has no loop, no counter, no cell to put "two so far" into.

And counting is exactly a loop: walk the items, increment a number. The model instead produces the total in one motion, by eye. On short words the guess often lands — which is why it looks like it can count. On a longer word the illusion falls apart.

Which is also precisely why it fumbles long multiplication and "how many words are in this paragraph".

How to fix. Don't make the model count — make it write code that counts:

Count how many times the letter "r" appears in "strawberry". Don't count in your head: write and run a short Python snippet, and take the answer from the result.

If the model has access to tools, it will run the code and return the exact number. The counting is then done not by a language model but by an ordinary interpreter, which never gets it wrong. The trick generalises: hand anything requiring exact arithmetic to code.

Cause 3: reasoning models get it right more often — not always

You may have tried this on a recent model and got the right answer. That doesn't cancel the causes above — the model just routed around them itself.

Reasoning models write out intermediate steps before answering. And among those steps is often exactly what we do by hand: the model spells the word out, numbers the letters and counts down the list. It hasn't "learned to see letters" — it built itself a crutch.

Two conclusions follow. One: on simple words this works, and works well. Two: there's no guarantee. Make the word longer or add conditions ("how many r's across these three words, excluding the last one") and the spelling-out step may not appear. The error comes back, confident tone included.

What to do in practice

Three habits and the topic is closed:

  • Exact numbers go to code. Letters, characters, words, sums, percentages. The phrase "write and run code" turns guessing into computing.
  • Need the answer in chat? Spell it out first. Ask for the items listed one by one, then counted. One extra step, and accuracy jumps.
  • Don't accept a number because of the tone. A model's confidence is unrelated to its correctness: it sounds identical when right and when wildly off.

And the general rule that makes life with AI much easier: models are excellent with meaning and poor with symbols. Summarise, explain, rephrase, spot the hole in an argument — that's their work. Counting exactly is work for code.

So AI can't be trusted with maths?

It can — just not as a calculator, more as a person who understands the problem. A model is great at choosing an approach, explaining the reasoning and catching a trap in the wording. Let code do the arithmetic and you get both the understanding and the precision.

Then why does it count correctly in code?

Because in code it isn't the one counting. The model writes word.count("r") — an ordinary line of the kind it has seen a million times. An interpreter then runs it, keeping a real counter over real characters. The model is the author of the instruction here, not its executor.

Become an AI architect — don’t just read about AI

The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.

About the Academy
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →