TL;DR
CAPEL (Can LLMs Track Their Output Length) is a method that plugs a length counter right into the text generation process. After every sentence, the model sees a feedback line like <words_used=87> and adjusts what comes next so it lands on the target length.
The researchers found a paradox: LLMs can count words in someone else's text just fine, but they lose count in their own. The longer the output, the worse the estimate. For 50-150 token texts, models are off by about 30 tokens on average; for 250-350 tokens, it's already 90. Ask for "300 words" and you get 250 one time, 370 the next. Why? The model is focused on content, not on counting. It doesn't keep an exact tally "in its head" — it writes like a person drafting without a word counter.
CAPEL fixes this with an external tool: it pauses generation at sentence boundaries, inserts the exact count (tokens/words/sentences), and resumes. The model sees "87 of 150 words used" → realizes 63 are left → adjusts pace and depth. The method works training-free (no fine-tuning needed) and gets even better after simple SFT on examples with feedback.
Want this for your own case? Apply this study to your task: AI adapts its method to what you are working on and writes the prompt.
Method Blueprint
Training-free (one request, but with interruptions):
STEP 1: Prompt with instructions + target length
↓
STEP 2: Generate up to the end of a sentence
↓
STEP 3: Insert feedback: <words_used=N>
↓
STEP 4: Continue generating → repeat steps 2-3
↓
RESULT: Text of exactly the right length
Note: In a regular chat you do the interruptions by hand. Through the API you can automate them.
Example
Task: Write an apartment listing for Zillow — exactly 150 words (the limit for a featured listing without truncation).
Prompt:
Write a listing for a two-bedroom apartment in Chicago (Lincoln Park, 5 minutes from the L,
600 sq ft, 8th floor, brick building, fully renovated, price $650,000).
REQUIREMENT: Exactly 150 words.
While you write, I'll give you feedback on the current length in the format
<words_used=N>. Use this information to hit the target exactly.
Begin:
(After every 2-3 sentences, stop the generation, count the words by hand
or with a word-count tool, insert: <words_used=47>, and continue)
Result:
The model will write the listing in chunks. After each piece of feedback it adjusts its pace: if it's short on words, it expands the details (renovation, layout, neighborhood); if it's close to the limit, it wraps up. The final text lands in the 145-155 word range instead of the usual "120 one time, 180 the next."
Why It Works
LLMs can't keep a running count in their heads while generating. The attention mechanism focuses on the meaning of the next token, not on counting the previous ones. The longer the text, the more the estimation error piles up — like someone writing without a word counter who just has a vague sense of "a couple more paragraphs."
But LLMs are great at following explicit instructions and handling structured input. The counter <words_used=87> is a clear signal the model reads as "task progress." It sees the gap between the current value (87) and the target (150) → tunes the detail and length of the next part.
Feedback is inserted at sentence boundaries, which keeps the text flowing naturally. The model doesn't break off mid-thought; it gets the update at a "safe point."
Control knobs:
- Feedback frequency: Insert after every sentence (maximum precision) or every 2-3 (faster, but less precise). For short texts (under 100 words), 2-3 insertions are enough.
- Length unit: Swap
<words_used=N>for<tokens_used=N>or<sentences_used=N>to fit your task. - Tolerance: You can add "±5 words is fine" to the prompt — the model will wrap up more gracefully.
Prompt Template
Task: {describe the task}.
REQUIREMENT: Exactly {number} {words/tokens/sentences}.
While you write, I'll give you feedback on the current length in the format
<{words/tokens/sentences}_used=N>. Use this information
to hit the target length exactly.
Begin:
What to fill in:
- {describe the task} — the specific task with context
- {number} — target length (100, 250, 15...)
- {words/tokens/sentences} — pick your unit of measure
After every 1-3 sentences:
1. Stop the generation
2. Count the length (by hand, with a word-count tool, or ask another LLM chat: "How many words are in this text: [paste text]")
3. Insert: <words_used=N>
4. Continue generating
🚀 Quick start — paste into the chat:
Here's the CAPEL template for precise length control. Adapt it to my task: [your task].
Ask me questions to fill in the fields.
[paste the template above]
The LLM will ask for the target length, the unit (words/tokens/sentences) and task details — because the method needs precisely worded requirements. It will take the pattern from the template and adapt it to your task.
Limitations
⚠️ Manual interruptions in chat: Without the API, you have to stop the generation, count words and insert feedback by hand. That's 3-5 iterations for a 150-300 word text — about 2-3 minutes.
⚠️ Quality trade-off on open-ended questions: On tasks where a precise answer of fixed length matters (e.g., "explain quantum physics in exactly 100 words"), the training-free version may "pad" its way to the limit with fluff. The SFT version solves this.
⚠️ Effectiveness depends on the model: Stronger models (8B vs 4B parameters) interpret feedback better and get more precise results. Weaker models improve too, just less.
How They Tested It
A team from Xiamen University and Alibaba tested the hypothesis in three stages. First, they took 1,000 texts of varying length (100-400 tokens) from three models (LLaMA-3.1-8B, Qwen3-4B, Qwen3-8B) and asked the models to estimate the length of their own output. The result was surprising: the error grows linearly with length. For short texts (50-150 tokens) the MAE was ~30; for long ones (350-450) it was already ~90 tokens. So a model that generated 400 tokens might think it wrote 310 or 490.
Then they tested the training-free approach on two tasks: summarization (GovReport, 973 documents) and biographies (183 people). They compared a baseline (a plain "write N words" prompt), ICL (a one-shot example), Feedback (their method), ICL+Feedback and Markergen (a competitor with three-stage generation). They measured MAE (mean length error) and PM (the share of texts landing within ±10 words of the target).
The results were a breakthrough: on Qwen3-8B for summarization, PM jumped from 15% (baseline) to 58% (Feedback) for tokens, and from 6% to 47% for words. For sentences — from 36% to 79%. Text quality (rated by DeepSeek-V3 on coherence, consistency, relevance) dipped only slightly: from 4.96 to 4.84 on a 5-point scale.
The final test was SFT on open-ended questions (ELI5, 10K training examples). They trained the model on its own answers with adjusted target lengths (Algorithm 1: if the model generated 287 words, the dataset says "target length 287±5"). They found a 4× gain in training efficiency: SFT+Feedback reaches the baseline SFT result in 32 steps instead of 128. Answer quality (correctness, helpfulness) doesn't drop, and token-level PM rises from 30% to 48%.
An unexpected finding: the method generalizes to other units. Trained on tokens/words/sentences, the model even handles counting characters (character-level) — though it was never trained on them. This suggests the feedback doesn't teach it to "count words" so much as to "track progress toward a constraint" in general.
Resources
Can LLMs Track Their Output Length? A Dynamic Feedback Mechanism for Precise Length Regulation
Meiman Xiao, Ante Wang, Qingguo Hu, Zhongjian Miao, Huangjun Shen, Longyue Wang, Weihua Luo, Jinsong Su
Xiamen University, Alibaba International Digital Commerce Group, Li Auto Inc.