Apply to my task
arXiv:2601.01768 ★ 78 Jan 5, 2026

CAPEL: A Live Word Counter for Precise Length Control

Key result

The paradox: LLMs are great at counting words in someone else's text but lose count disastrously in their own. Ask for "300 words" and you get 250 one time, 370 the next. The reason: the model is busy with content and keeps the count "in its head" — like a person writing without a word counter. CAPEL lets you generate text that hits the limit precisely (±5 words instead of ±50). Need exactly 150 words for an ad card? You'll get 147-153, not "somewhere around 150." The trick: it moves the counting outside the model. The model writes 2-3 sentences → sees `` → understands "103 of 150 left" → adjusts its pace. 95% accuracy instead of 30% on 100-300 word texts.

01

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.

02

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.

03

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."

04

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.
05

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.

06

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.

07

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.

08

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.

Research digest

Key result

The paradox: LLMs are great at counting words in someone else's text but lose count disastrously in their own. Ask for "300 words" and you get 250 one time, 370 the next. The reason: the model is busy with content and keeps the count "in its head" — like a person writing without a word counter. CAPEL lets you generate text that hits the limit precisely (±5 words instead of ±50). Need exactly 150 words for an ad card? You'll get 147-153, not "somewhere around 150." The trick: it moves the counting outside the model. The model writes 2-3 sentences → sees `` → understands "103 of 150 left" → adjusts its pace. 95% accuracy instead of 30% on 100-300 word texts.

Principle

Generation happens in chunks with interruptions — not all at once, but piece by piece. The model writes to the end of a sentence → you stop it → insert the exact count `` → continue. It sees the gap between the current value (87) and the target (150) → tunes the detail of the next part. Close to the limit — it wraps up. Far from it — it builds out the details. It's like GPS in a car: instead of just "drive 10 miles," it tells you every 2 miles "8 to go... 6 to go..." — and the driver adjusts speed to the destination.

Why it works

The attention mechanism focuses on the meaning of the next token, not on counting the previous ones. An LLM writes like a person — it senses "a couple more paragraphs" but doesn't keep an exact tally. The longer the text, the bigger the error: off by 30 for 50-150 tokens, already by 90 for 250-350. An external counter is a clear signal of task progress. The model reads `` as "you're 58% of the way there" → pace control kicks in. And LLMs are excellent at following explicit instructions — hence the jump from 30% to 95% accuracy. Feedback is inserted at sentence boundaries — the model doesn't break off mid-thought and gets the update at a "safe point."

When to apply

Content marketing and ads → when the platform truncates at a limit (Zillow's 150 words for a featured listing, Google Ads' 30 characters for a headline, email newsletters with a 50-70 word preview). Technical documentation → exactly one letter-size page for a spec, an API endpoint description in 200 words. Educational content → assignments like "explain quantum physics in exactly 100 words" (though here the training-free version may pad with fluff to hit the number — SFT is better). NOT a fit: Creative writing where the limit is loose ("about a page") — the juice isn't worth the squeeze.

Mini recipe

1. Set a hard limit in the prompt: "Exactly 150 words. I'll give you feedback in the format ``. Use this information to hit the target exactly." 2. Generate in chunks: After every 1-3 sentences, stop the generation (the "Stop" button in chat or `max_tokens` in the API). 3. Count and insert: Count the words by hand, with a word-count tool, or ask another LLM chat: "How many words: [paste text]". Insert the line `` into the conversation. 4. Keep going to the target: The model sees the number → adjusts its pace → writes the next chunk. Repeat steps 2-3 until you reach the limit (usually 3-5 iterations for 150-300 words). 5. Tune the frequency: For short texts (under 100 words), 2-3 insertions are enough. For long ones (300+), insert after every sentence — you'll get a more precise result.

Examples

[BAD]: `Write a two-bedroom apartment listing for Zillow — 150 words. Chicago, Lincoln Park, 600 sq ft, fully renovated, $650,000.` (Result: 120 words one time, 185 the next — the platform truncates it or shows an incomplete listing) [GOOD]: `Write an apartment listing for Zillow. REQUIREMENT: Exactly 150 words. While you write, I'll give you feedback on the current length in the format . Use this information to hit the target exactly. Details: Chicago, Lincoln Park, 5 minutes from the L, 600 sq ft, 8th floor, brick, fully renovated, $650,000. Begin:` → The model writes 3 sentences (40 words) → you insert `` → it continues knowing "110 to go" → 50 more words → `` → a final push of 60 words. Result: 147-153 words.

In plain words

Today's AI models are brilliant talkers who absolutely cannot count. Ask ChatGPT for exactly 100 words and it'll nod along, then hand you 130 or 80, because its attention mechanism is built for meaning, not arithmetic. To the model, writing is a creative flight where it simply can't see how far it has flown. So every attempt to cap the length turns into a guessing game, with the error growing with every new sentence.

It's like trying to slice salami into even 5-gram slices blindfolded. You sort of feel the weight of the knife, but without a scale each slice ends up thinner or thicker than the last. Instead of a neat platter, you end up with a messy pile that won't fit in the container. The model just "forgets" to count words while it's busy picking pretty adjectives.

CAPEL tackles the problem head-on: it adds an "outside eye" to the generation process. After every sentence, the system forcibly inserts a technical line like <words_used=87>. That makes the model literally trip over reality and see how much room is left before the finish line. You get dynamic feedback: the model realizes the limit is near and starts trimming its thought sharply or, the other way around, padding to reach the number.

This approach is a lifesaver for any content with hard limits, whether it's product descriptions for marketplaces where an extra word just gets cut off, or social posts with a character cap. It was tested on specific tasks, but the principle is universal: if you need to cram a complex idea into a rigid spec, a regular prompt won't cut it. You need an external counter that slaps the model's wrist every time it gets lost in the details.

Bottom line: stop hoping the AI will figure out on its own when to shut up. Without a method like CAPEL, the model will always flub word counts, because it's a poet, not an accountant. Want precision? Make the model see the running result in real time. That's the only way to get text that fits the limit perfectly without collapsing into incoherent mush mid-sentence.

AI lab assistant

Apply this study to your task

Describe what you're working on. AI takes the method and the measured results from this paper and adapts them to your case, or writes a ready prompt built on them.

Based on CAPEL: A Live Word Counter for Precise Length Control arXiv:2601.01768

Sign in to apply this study New accounts get 50 free credits.