How to Get AI to Hit a Specific Word Count
Asking for exactly 500 words gets you somewhere between 380 and 720. The fix is not asking more firmly, because no amount of instruction installs a counter.
Ask an AI model to hit a word count of exactly 500 and you will get somewhere between 380 and 720 words. Ask for "about 500 words" and the range widens. This is not a prompting failure you can fix by asking more firmly, and the reason is worth ten seconds of your attention because it tells you which workarounds are real.
The reliable approach is to stop asking for a word count and start constraining the structure that produces one.
Why AI cannot hit a word count on request
A model generates one token at a time, and it does not know how many words it has produced unless it tracks them explicitly. Words are not the unit it works in either. It emits tokens, which map to words at a ratio somewhere near 0.75 words per token in English and vary by vocabulary, punctuation, and formatting. If you want to see the split for a given string, the Hugging Face tokenizers documentation covers running one locally.
So "write 500 words" asks the model to hit a target in a unit it does not count, using a mechanism that has no counter. It approximates from a learned sense of how long 500 words looks. That sense is decent and not precise, and it is the same limitation behind why AI models are bad at counting.
Knowing this rules out a whole family of attempts: repeating the number, bolding it, adding "exactly", threatening consequences. None of them install a counter.
What actually works, in order
1. Constrain structure instead of length
This is the highest-leverage change by a distance. Length is an outcome of structure, and structure is something a model can follow precisely.
Instead of:
Write a 600 word overview of our returns policy.Write:
Write an overview of our returns policy with:
- One opening paragraph, 3 sentences
- Four sections, each with an H3 and 2 short paragraphs
- One closing paragraph, 2 sentences
Keep paragraphs to 40 to 60 words.The second version lands within a tight band, run after run, because every constraint is countable at the point the model is writing it. Sentences and sections are things it tracks naturally. Total words are not.
2. Give a range, not a number
If you must specify words, specify a band. "Between 550 and 650 words" outperforms "600 words" because it matches how the model approximates. A single number reads as a target it will miss in either direction; a band reads as a constraint with slack, and models respect bands well.
Keep the band at roughly plus or minus 10%. Tighter is aspirational, looser stops steering anything.
3. Show an example of the right length
A single sample of correct output does more than three sentences of instruction. The model matches the shape of what it sees, so an example at 480 words pulls the next output toward 480 words. This is ordinary few-shot behaviour applied to form rather than content, and it is why few-shot prompting keeps outperforming careful description.
The cost is context. One example is usually enough for length.
4. Ask for a revision pass
Length is much easier to fix than to hit. A second turn saying "this is 740 words, cut it to under 600 by removing repetition, keep every section heading" works reliably, because now the model has the actual text in front of it and editing down is a different task from generating to target.
Two turns cost more than one and produce a result you do not have to check. For anything going in front of a customer, that is the correct trade.
5. Count it yourself and loop
For automated pipelines, stop negotiating. Generate, count words in your own code, and if it is outside the band send it back with the measured number and the delta. Three attempts maximum, then take the closest.
def to_length(generate, lo, hi, tries=3):
text = generate()
for _ in range(tries):
n = len(text.split())
if lo <= n <= hi:
return text
verb = "Expand" if n < lo else "Cut"
text = generate(f"That draft is {n} words. "
f"{verb} it to between {lo} and {hi} words. "
f"Keep all headings and the argument order.")
return textDeterministic, cheap, and it removes the problem rather than mitigating it. The general shape of this argument is in getting consistent AI output every time.
The special case of hard limits
Some limits are not preferences. A meta description that must sit under 155 characters, an SMS body under 160, a field with a database constraint.
For those, never rely on the model. Generate, measure, and truncate or regenerate in code. A model asked for "under 155 characters" will produce 160 often enough to break production, and the failure will be intermittent, which is the worst kind. Treat the model as a drafting tool and your code as the enforcement layer.
Character limits are also where the token mismatch bites hardest, since a single emoji or an accented character can cost more than expected. The counting logic belongs in your language, not in the prompt.
FAQ
Why does the model overshoot more often than it undershoots?
Generation continues until the model decides to stop, and elaborating is the more common learned behaviour. Explicitly saying "stop when the last section is complete, do not add a summary" removes one of the usual sources of overrun, along with the reflex to conclude.
Does asking for tokens instead of words help?
Slightly, because tokens are closer to what the model produces, but it still has no counter. It also makes the instruction harder for a human collaborator to reason about. Use structure.
Does max_tokens solve this?
It caps output, it does not target it. You get a hard truncation mid-sentence rather than a shorter finished piece. Useful as a runaway guard, not as a length control. Our note on estimating tokens for an AI task covers the sizing side.
Does the model count better if I ask it to count as it writes?
It improves a little and costs a lot, because you are asking for a running tally in the output. Counting after the fact in your own code is more accurate and free.
Does this differ between models?
Bands and structural constraints work across all of them. Absolute accuracy on a single number varies, and none of them are reliable enough to build on. For the broader technique set, see our prompt engineering guide.
How did this land?
About the author

Developer Advocate
Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.


