Zenaique

A response comes back with finish_reason = 'length'. Which interpretation is correct?

MCQ·Medium·4.0 · 0·~1 min·Asked atDustOpenAIShopify·Relevant atAnthropic
Attempt it
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

finish_reason is a small, discrete field in LLM API responses that is easy to ignore, but it is the only signal of why generation ended. Production stacks that ignore it produce silently broken outputs; stacks that handle it catch a whole class of bugs at the source.

The values map to three different termination causes, and 'length' is the one that needs the most active handling. A 'stop' termination means the response is complete and ready to use. A 'length' termination means the response was truncated, and consumers must decide whether to extend, retry, or fail. Logged per route, the distribution of values is also a useful monitoring signal.

The three termination causes

Decoding can end for three distinct kinds of reason.

Model-driven: the model's output caused the stop. The model can sample its EOS (end-of-sequence) token, a special token that training taught it to emit at natural completion points. Or the caller can supply stop sequences (strings like '\n\nHuman:' or '</response>') that the runtime checks against the decoded text after each token, halting on a match. Both surface as 'stop' in OpenAI's enum; Anthropic separates them as 'end_turn' and 'stop_sequence'. A tool call is also model-driven: the model chose to call a tool, so the runtime stops and returns 'tool_calls' (OpenAI) or 'tool_use' (Anthropic) for the caller to run it.

Length-driven: a numeric cap on output length was hit before the model chose to stop. The cap is max_completion_tokens in OpenAI Chat Completions (max_tokens is deprecated there), max_output_tokens in OpenAI's Responses API, maxOutputTokens in Gemini, and max_tokens in Anthropic's Messages API. On reasoning models the cap also counts reasoning tokens. This surfaces as 'length'.

Policy-driven: a safety or moderation layer intervened, whatever the model would have produced. These get their own values: 'content_filter' (OpenAI), 'refusal' (Anthropic), 'SAFETY' and related values (Gemini).

These three classes correspond to different parties making the stop decision: the model (model-driven), the runtime budget check (length-driven), and an external policy (policy-driven). Each requires different downstream handling. Conflating them is the source of most finish_reason bugs in production code.

Why option C is correct and the others are not
Operational handling of 'length' terminations
Reasoning models and the budget interaction
Observability: finish_reason as a first-class signal
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
CauseOpenAIAnthropicGoogle 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''SAFETY' (and related values such as 'PROHIBITED_CONTENT')
Tool / function call emitted'tool_calls' ('function_call' is deprecated)'tool_use''STOP' with a function call in the response (no separate value)

Real products, models, and research that use this idea.

  • OpenAI Chat Completions returns finish_reason = 'length' when max_completion_tokens (or the deprecated max_tokens) 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.
Sign in to see more production examples.

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?
A

Resubmit the original prompt plus the truncated assistant output as a partial assistant message, on APIs that accept one. The model continues from where it stopped, though sampling may take a different path than the original run would have. Edge cases: a UTF-8 character split across the last token and the next one, mid-tool-call truncation (the JSON is malformed and cannot be parsed), and reasoning-model continuations where the hidden reasoning state is not exposed and resumption is approximate.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • The three classes of termination causes (model-driven, length-driven, policy-driven)

  • Why 'length' specifically means max_tokens was hit before any natural stop

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is the KV cache in transformer inference?
Flashcard·Easy