<aside>

On this page:

</aside>

<aside>

Expanse Docs

🧠 Product Docs

🤖 Prompting Tips

LLM Directory

Prompting Tips & Tricks

Prompt Library

💻 Use Cases

For Work

For Fun

📚 Resources

Prompt Engineering Resources

🍄 About Expanse

Meet the team

</aside>

Getting AI to count words precisely can be surprisingly tricky. Here's why it happens and how to solve it with a simple technique that works every time.

<aside>

💡 TLDR

Why can't AI count words accurately?

You've probably noticed this: you ask AI to write exactly 500 words, and it gives you something that's clearly longer or shorter. When you point this out, the AI often insists it's correct. The issue comes down to how AI processes language. While you think in terms of individual words, AI thinks in tokens—chunks of text that might be whole words, parts of words, or even punctuation marks.

What are Tokens?

Tokens are the basic units of text the AI models process. Unlike humans, AI interprets text in groups or clusters of characters instead of word-by-word. A common approximation is that one token corresponds to about 0.75 words.

For Example:

How can I calculate Tokens?

How do I make AI count accurately?

While AI models don’t know how to “count” they are skilled at generating code. So, instead of prompting an AI to count text, instead, ask it to write code that counts.

When you request a word count verification script, you're asking the AI to step outside its token-based thinking and use actual word-counting logic. Python's word counting is precise and matches how humans count words.

<aside> đź’ˇ

NOTE: While the output will never match the precise word count, this prompting method helps the AI generate responses that are significantly closer to your target word count.

</aside>

The Magic Prompt: Using Python Code to Count

Add this to the end of any prompt where you want to constrain the output’s word count:

After generating the response, use Python to:

Count and verify the output is ≤ {{NUMBER OF WORDS}} ±5% words
If it exceeds the limit, please revise until it complies.

Please write and execute the Python code as part of your response. 

This approach works because:

<aside> đź’ˇ

The AI will often adjust its content after running the verification script, giving you more accurate results than asking for word counts alone.

</aside>

Example Prompts

Here are three real-world examples showing how to integrate word count verification into different types of content creation:

eBay Listing Title and Description

Academic Essay

Anki Flashcard

<aside> đź’ˇ

You can view a list of all of our top Prompts in our

</aside>

Tips and Tricks

While this word count verification technique is highly effective, there are a few practical considerations to keep in mind as you start using it regularly.

1. Save this Prompt Pattern

To save time, store this phrase template in your Role or as a Prompt:

After generating the response, use Python to:

Count and verify the output is ≤ {{NUMBER OF WORDS}} ±5% words
If it exceeds the limit, please revise until it complies.

Please write and execute the Python code as part of your response. 

2. Use Focus Mode

If you're creating several pieces of content with different word counts (like multiple blog posts or several product descriptions), consider using Focus Mode. This is essentially the same as starting fresh conversations for each prompt. The AI will only respond to the current message you send in the thread, ignoring previous conversation history.