Skip to content

Definition

The stop_reason field on a response tells you why Claude stopped generating; it drives whether the Agentic loop continues or exits.

Key points

  • end_turn — Claude finished naturally (done; loop exits).
  • tool_use — Claude wants a client tool run; the only value that continues the loop (execute → append tool_result → resend).
  • max_tokens — output truncated at the token limit.
  • stop_sequence — a configured stop sequence was hit.
  • pause_turn — a server-tool loop hit its iteration cap; resend the conversation unmodified to continue (see pause_turn handling).
  • refusal — safety-driven stop; output may not match the requested schema.
  • model_context_window_exceeded — on 4.5+ models the request is accepted and generation stops gracefully here rather than a 400 (opt in on earlier models via beta header model-context-window-exceeded-2025-08-26).

Why it matters for the exam

  • Classic D1 trap: "which stop reason continues the agentic loop?" Answer is tool_use alone. Also tests knowing pause_turn needs a resend and model_context_window_exceeded is graceful (not a 400) on 4.5+.

Common gotchas

  • refusal output may not conform to your schema — don't assume valid JSON.
  • If input alone exceeds the window you get a 400 invalid_request_error ("prompt is too long") on every model — model_context_window_exceeded only applies when input + max_tokens overflow during generation.

See also

Sources