πŸ’‘ When even AI struggles with “word limits”…

Every time I fill out a form and that red warning appears "max. X words", I feel a slight frustration. After all, I spent time building a complete argument, and then the form says: "summarize, or you can't proceed." (lol)

This week, AWS researchers published a useful paper on this problem:
"Plan-and-Write: Structure-Guided Length Control for LLMs without Model Retraining."

The research investigates whether LLMs can actually write within a pre-established word limit β€” something that, if you've tested it, you know usually doesn't work.

The famous "vanilla prompt" "Write a 200-word text about…" typically fails miserably.

But what the authors proposed is brilliant: use prompt engineering to structure the model's reasoning. With this, they managed to approximate the desired result without needing to reconfigure the model with fine-tuning and other techniques. My tests were in a different domain (legal texts), but the paper's principles applied.

After several hours of experiments, I arrived at a metaprompt with results within the expected margin even for longer ranges (500+ words), where degradation tends to be greater.

I tested it in practical scenarios β€” fictitious complaints to regulatory agencies β€” and the results were within the margin. With the right prompt, technical impossibility can become a matter of linguistic engineering.

Test it yourself with the metaprompt I developed below (just define the task and word count, then paste the metaprompt).

“`markdown

<h1>Plan-and-Write</h1>

<hr/>

TASK: [INSERT TASK] in EXACTLY {N} WORDS.

<hr/>

<h2>COUNTING RULES (CRITICAL)</h2>

<ul>
<li>Hyphenated words = 1 word (e.g., "state-of-the-art")</li>
<li>Numbers = 1 word (e.g., "2025", "$500")</li>
<li>Contractions = 1 word (e.g., "don't", "it's")</li>
<li>Acronyms = 1 word (e.g., "GDPR", "FDA")</li>
</ul>

<hr/>

<h2>MANDATORY PROTOCOL</h2>

<h3>STEP 1 β€” Numbered Planning</h3>

List ALL words numbered from 1 to {N}:
1. first
2. second

{N}. last

⚠️ COUNT word by word. If wrong, restart.

<hr/>

<h3>STEP 2 β€” Final Text</h3>

Rewrite as coherent paragraph <strong>WITHOUT numbers</strong>.
Keep EXACT {N} words from Step 1.

<hr/>

<h3>STEP 3 β€” Validation (MANDATORY)</h3>

Count the words in the final text and confirm:
<strong>"βœ“ Verified: [N] words"</strong>

If β‰  {N}, redo EVERYTHING from Step 1.

<hr/>

<h2>ADJUSTMENTS BY SIZE</h2>

<ul>
<li>{N} ≀ 100 β†’ ZERO tolerance </li>
<li>{N} 101–500 β†’ Β±1 word acceptable </li>
<li>{N} > 500 β†’ Β±2% acceptable (prioritize coherence)</li>
</ul>

<hr/>

<h2>EXAMPLE (15 words)</h2>

<strong>STEP 1 β€” Planning</strong>
1. The
2. agency
3. imposed
4. a
5. $50,000
6. fine
7. against
8. the
9. company
10. for
11. misleading
12. advertising
13. about
14. extended
15. warranty

<hr/>

<strong>STEP 2 β€” Final Text</strong>
The agency imposed a $50,000 fine against the company for misleading advertising about extended warranty.

<hr/>

<strong>STEP 3 β€” Validation</strong>
βœ“ Verified: 15 words

<hr/>

“`

Leave a Reply