AI / Claude Models Basics Interview Questions
What are the different stop_reason values in Claude API responses?
Every Claude API response includes a stop_reason field indicating why Claude stopped generating. Understanding stop reasons is essential for building robust applications — especially for tool use and handling truncated responses.
| Value | Meaning | Action required? |
|---|---|---|
| end_turn | Claude naturally finished its response | No — response is complete |
| max_tokens | Response was cut off at the max_tokens limit — may be incomplete | Increase max_tokens or handle partial response |
| stop_sequence | Claude generated one of the stop sequences you defined | No — intentional stop point reached |
| tool_use | Claude wants to use a tool — response contains a tool_use block | Yes — execute the tool and return results |
| pause_turn | Claude paused and is waiting for input (streaming only) | Resume the stream or provide input |
| refusal | Claude declined to continue for safety reasons | Review the request; no further action if appropriate |
response = client.messages.create( model="claude-opus-4-8", max_tokens=1024, tools=[...], # defined tools messages=[{"role": "user", "content": "What is the weather in London?"}] ) match response.stop_reason: case "end_turn": print("Complete:", response.content[0].text) case "tool_use": # Claude wants to call a tool tool_block = next(b for b in response.content if b.type == "tool_use") result = execute_tool(tool_block.name, tool_block.input) # Send result back to Claude case "max_tokens": print("Truncated! Increase max_tokens.") case _: print(f"Stopped: {response.stop_reason}")
When stop_reason is tool_use, the application must execute the requested tool and send the result back to Claude in a new message for the conversation to continue.
More Related questions...