Prompt-Based One-Shot Exact Length-Controlled Generation with LLMs
Juncheng Xie, Hung-yi Lee

TL;DR
This paper introduces a prompt-based method that enables large language models to generate text of an exact desired length, such as words or characters, without fine-tuning, by using countdown markers and explicit counting rules.
Contribution
The paper presents a novel prompt engineering technique that achieves precise length control in LLM outputs through a simple, one-shot prompt without additional training or iterative sampling.
Findings
Achieves over 95% length compliance on MT-Bench-LI with GPT-4.1
Outperforms draft-then-revise baseline in length accuracy
Maintains answer quality while controlling length
Abstract
Controlling the length of text produced by large language models (LLMs) remains challenging: models frequently overshoot or undershoot explicit length instructions because they cannot reliably keep an internal token count. We present a prompt-based, one-shot strategy that compels an off-the-shelf LLM to generate exactly a desired number of tokens - words (English) or characters (Chinese) - without any fine-tuning or iterative sampling. The prompt appends countdown markers and explicit counting rules so that the model "writes while counting." We evaluate on four settings: open-ended generation (1-1000 tokens), XSUM summarization, MT-Bench-LI instruction following, and the LIFEBENCH equal-length track. On MT-Bench-LI, strict length compliance with GPT-4.1 leaps from below 30% under naive prompts to above 95% with our countdown prompt, surpassing the popular draft-then-revise baseline,…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
