APIIntermediateClaude API
If a tool fails, send the error back to Claude with is_error
An empty result is taken as valid data; with is_error set to true Claude knows it failed and can change its plan.
When your code runs a tool and it fails, do not return empty and do not swallow the exception. Send a tool_result with is_error set to true and a clear message. That way the model can try another route, ask for clarification or stop, instead of reasoning further from a false premise.
Example
def run_tool(tool_use):
try:
result = execute(tool_use)
return {"type": "tool_result", "tool_use_id": tool_use.id, "content": result}
except Exception as e:
return {"type": "tool_result", "tool_use_id": tool_use.id,
"is_error": True, "content": f"Tool failed: {e}"}