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/>
“`