Skip to content
mentoor

Topic 3 of 5 · 4 min read

Spelling and counting token traps

Goal: Identify a task that fails because the model sees tokens instead of letters and choose a workaround such as running code or spelling the word out.

A language model sees tokens, not letters, so tasks that depend on individual characters, such as counting letters, reversing words or doing long arithmetic, are unreliable unless you give it a tool or spell the text out. The model can sound sure and still be wrong.

Check yourself · 1 of 3

Why can a strong model get "How many r's are in strawberry?" wrong?

Choose one answer

Why it matters

These failures look silly, and they catch careful people off guard. A model that writes a good legal summary may tell you "strawberry" has two r's. If you trust it for a word count, a character limit or a checksum, you ship a mistake. Knowing the cause tells you which tasks to double check.

Why it happens

Take the word "strawberry". A tokenizer might cut it into "str", "aw" and "berry". The model gets three number codes, not ten letters. It has to recall how each chunk is spelled from its training, and that recall is patchy. The same holds for:

  • Counting letters or characters. "How many e's are in this sentence?"
  • Reversing or sorting letters. Spelling a word backwards, or putting letters in alphabetical order.
  • Exact length limits. "Write a headline of exactly 60 characters."
  • Long numbers. A number such as 48,291,057 may be cut into several chunks, and digit-by-digit arithmetic on it is easy to get wrong.
  • Rhymes and wordplay across unusual spellings.

Newer models are better at some of these, partly because they were trained on them or can run code. Do not rely on that. Test the task on your model.

What to do instead

  1. Spell it out. Ask the model to first write the word with a dash between letters ("s-t-r-a-w-b-e-r-r-y"), then count. Each letter now becomes its own token, so the task becomes easy.
  2. Use a tool. If your assistant can run code or a calculator, ask it to. Code counts letters and adds numbers exactly.
  3. Check by hand. For a character limit, paste the result into a counter in your editor.

For engineers, the exact version is two lines:

word = "strawberry"
print(word.count("r"))  # 3

Before and after

Before: "How many r's are in strawberry?" The model answers "2" with confidence.

After: "Spell strawberry one letter per line, then count the r's." The model lists the ten letters and counts three.

What goes wrong

  • People read a confident tone as a sign of a correct answer.
  • People trust a model for a hard character limit in a title, ad or SMS.
  • People ask for arithmetic on long numbers in plain chat, with no calculator or code tool.

Examples

Fix a character limit

Task: An ad headline must be 60 characters or fewer.

Weak: "Write a headline of exactly 60 characters." The model gives a headline it says is 60 and is actually 71.

Better: Ask for five options, then paste each into a character counter or ask the assistant to run code that prints the length of each. Keep the first one that fits.

Long-number arithmetic

Task: Add 48,291,057 and 7,638,942.

Weak: Ask in plain chat and trust the answer.

Better: Ask the assistant to use its calculator or code tool, or add the numbers yourself and ask the model only to explain the steps. The exact result is 55,929,999.

Key points

  • The model sees tokens, so it cannot directly see the letters inside a token.
  • Counting letters, reversing words, exact character limits and long arithmetic are the classic failures.
  • A confident tone does not mean the answer is right.
  • Spelling the word out letter by letter makes the task much easier for the model.
  • When code or a calculator is available, let it do the exact work and use the model to explain.

Common mistakes

  • Trusting a confident answer to a letter-counting or length question.
  • Asking for an exact character count without any way to check it.
  • Doing arithmetic on long numbers in chat with no calculator or code tool.
  • Concluding that the model is weak overall because it fails these narrow tasks.

Check yourself · 2 of 3

You need a headline that is at most 60 characters. What is the most reliable approach?

Choose one answer

Check yourself · 3 of 3

Which task is MOST likely to cause a token-related mistake?

Choose one answer

Practice items, not counted towards your mastery.

Start here