A response comes back with finish_reason = 'length' which interpretation is correct?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.