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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
