Your model's answers are consistently too long. How do you control output length reliably?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Treat length as a spec you design for, not a number you ask for. Word-count instructions are approximate because models generate tokens and count words poorly. max_tokens is a hard cutoff, not a length instruction: hit it and you get a sentence chopped in half, which is worse than a long answer.
Full worked answer
Treat length as a spec you design for, not a number you ask for. Word-count instructions are approximate because models generate tokens and count words poorly. max_tokens is a hard cutoff, not a length instruction: hit it and you get a sentence chopped in half, which is worse than a long answer.
What works, roughly from most to least reliable:
- Structural constraints over counts. "At most three bullets, one line each" or "one sentence, then a table" is far more reliable than "under 150 words", because structure is easy for the model to track while it generates.
- Remove the cause. Look for phrases in your own prompt that push length up: "be thorough", "explain your reasoning", or a long, heavily formatted system prompt, since models mirror the style of the prompt they are given. Verbose few-shot examples are the worst offender, because examples beat instructions.
- Show the target length. One or two examples at the length you want anchor it better than any adjective.
- Use the API setting if the provider has one. Some providers expose a verbosity or effort parameter that shifts default length without prompt changes. On reasoning models the output cap usually covers reasoning tokens too, so a tight cap can starve the visible answer entirely.
- Give concision a reason. "Users read this on a phone inside a support widget" works better than "be concise", because the model can generalise from the reason to cases you did not list.
For hard limits, such as an SMS or a fixed UI field, validate after generation. If the output is over, regenerate with feedback or have a cheap model shorten it. Never rely on the prompt alone for a limit a downstream system enforces.
Measure length as a distribution on your eval set, the median and the p95, not by eyeballing three outputs. Length often shifts silently with a model upgrade, so put a length check in CI next to the quality score.
What a good answer covers
- Treat length as a spec you design for, not a number you ask for
- Word-count instructions are approximate because models generate tokens and count words poorly
- Structural constraints over counts
- Remove the cause
- Show the target length
Key terms: Structural constraints over counts · Remove the cause · Show the target length · Give concision a reason
In the glossary: Few-shot · Reasoning model · Eval set
Interviewer follow-ups to expect
Why does asking for exactly 100 words rarely produce 100 words?
How would you shorten answers without losing a caveat that legal requires?
What happens to visible output when a reasoning model hits its token cap?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep