A response comes back with finish_reason = 'length' which interpretation is correct?
finish_reason = 'length' means the runtime hit the max_tokens cap before the model emitted EOS or matched a stop sequence. It is a hard numeric truncation, not a content-driven stop.
Imagine asking someone to write you a story but giving them only 30 seconds. If they finish naturally before the timer runs out, they put a period at the end and hand it to you ('stop'). If the timer rings while they are still writing, they have to stop mid-sentence ('length'). The 'length' signal means the timer ran out, not that the story was finished. To get a complete answer you have to either give them more time, ask for a shorter story, or come back and ask them to keep writing where they left off.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
2 min: classify the three termination causes (content / length / policy), map each option to its enum, identify C as the max_tokens-cap case (= 'length'), and name the production handling (continuation calls, observability, structured-output gating).
| Cause | OpenAI | Anthropic | Google Gemini |
|---|---|---|---|
| EOS sampled (natural completion) | 'stop' | 'end_turn' | 'STOP' |
| Stop sequence matched | 'stop' | 'stop_sequence' | 'STOP' |
| max_tokens cap hit | 'length' | 'max_tokens' | 'MAX_TOKENS' |
| Safety / content policy | 'content_filter' | 'refusal' or stop_reason variants | 'SAFETY' |
| Tool / function call emitted | 'tool_calls' / 'function_call' | 'tool_use' | 'TOOL_CALL' |
Real products, models, and research that use this idea.
- OpenAI Chat Completions returns finish_reason = 'length' when max_tokens (or max_completion_tokens for o-series) is hit before EOS.
- Anthropic's Messages API uses stop_reason = 'max_tokens' for the same condition; the field name differs but the semantics match.
- Google Gemini returns finishReason = 'MAX_TOKENS' for truncation by cap, with the partial output in the candidates field.
- Production agent frameworks (LangGraph, LlamaIndex agents) check finish_reason before parsing tool calls; a 'length' termination skips JSON parse and triggers a continuation call.
- Reasoning-model APIs (o-series, Claude extended thinking) expose separate budgets for reasoning_tokens versus visible output; 'length' can fire on either.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow do continuation calls work mechanically, and what are the edge cases?
QWhy do reasoning models often hit 'length' even on short visible answers?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Reading finish_reason = 'length' as 'the model finished naturally and the answer is long'. It is the opposite: the answer was cut off because the runtime hit a numeric cap. Treating a 'length' termination as a complete response leads to silently truncated outputs.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.