How to Tell Claude a Tool Failed with is_error
Tools fail: a record isn't there, a service is down, an argument is wrong. When that happens, Claude still needs an answer to its tool call, or it can't go on. The is_error flag lets you send the failure back, so Claude can try again or explain the problem. This guide makes a library lookup fail, with real output from anthropic 2.14.0.
Syntax
{
"type": "tool_result",
"tool_use_id": <the tool_use block's id>,
"content": "<what went wrong>",
"is_error": True,
}
| Part | What it means |
|---|---|
tool_use_id | The id of the call that failed, as in any tool result |
content | The error message Claude reads |
"is_error": True | Marks the result as a failure instead of a result |
Anthropic's documentation: "When a client tool fails or a call is invalid, send a tool_result block with is_error set to true. Claude might then call the tool again with a new tool_use block, so limit how many retries your loop allows."
What It Costs
The Claude API is paid: Claude Opus 5.5 costs $4 per million input tokens and $20 per million output tokens. Each retry is another request that resends the whole conversation. The run below made three calls, 1,527 input and 289 output tokens in all, about $0.012.
Prerequisites
- A Claude API key, in a
.envfile asANTHROPIC_API_KEY=.... - The Anthropic Python SDK in a uv project. This guide uses anthropic 2.14.0, added with
uv add anthropic, on Python 3.15.2.
Step 1: Write a Tool That Can Fail
Create tool_error.py. The tool finds which shelf a book is on, and raises an exception when the library doesn't have it:
import anthropic
client = anthropic.Anthropic()
SHELVES = {"the glass orchard": "Shelf F-12", "rivers of salt": "Shelf N-04"}
def find_book(title: str) -> str:
shelf = SHELVES.get(title.lower())
if shelf is None:
raise LookupError(f"There's no book called {title!r} in the catalogue.")
return shelf
The error message says exactly what went wrong, with the title Claude asked for. Claude reads it, so a clear message helps it decide what to do next.
Step 2: Describe It to Claude
Add the tool's definition and the question. The question asks for a book that isn't in SHELVES:
tools = [
{
"name": "find_book",
"description": (
"Find which shelf of the library a book is on, by its title. "
"Use it whenever someone asks where to find a book."
),
"input_schema": {
"type": "object",
"properties": {
"title": {"type": "string", "description": "The book's title."},
},
"required": ["title"],
},
}
]
messages = [{"role": "user", "content": "Where can I find The Silent Orchard?"}]
Step 3: Send Failures Back with is_error
Add the tool loop. It runs each call inside try, and turns a LookupError into a result with is_error:
response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)
while response.stop_reason == "tool_use":
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type != "tool_use":
continue
try:
shelf = find_book(**block.input)
result = {"type": "tool_result", "tool_use_id": block.id, "content": shelf}
except LookupError as error:
result = {
"type": "tool_result",
"tool_use_id": block.id,
"content": str(error),
"is_error": True,
}
print(f"Tool: {block.name}({block.input}) sent back {result['content']!r}")
results.append(result)
messages.append({"role": "user", "content": results})
response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)
print("Claude:", response.content[-1].text)
- When
find_bookworks, the result carries the shelf, as usual. - When it raises
LookupError,exceptcatches it, and the result carriesstr(error), the error message, with"is_error": True. - Either way, the call gets a result, and the loop goes on: the script doesn't stop at the exception.
The complete script:
import anthropic
client = anthropic.Anthropic()
SHELVES = {"the glass orchard": "Shelf F-12", "rivers of salt": "Shelf N-04"}
def find_book(title: str) -> str:
shelf = SHELVES.get(title.lower())
if shelf is None:
raise LookupError(f"There's no book called {title!r} in the catalogue.")
return shelf
tools = [
{
"name": "find_book",
"description": (
"Find which shelf of the library a book is on, by its title. "
"Use it whenever someone asks where to find a book."
),
"input_schema": {
"type": "object",
"properties": {
"title": {"type": "string", "description": "The book's title."},
},
"required": ["title"],
},
}
]
messages = [{"role": "user", "content": "Where can I find The Silent Orchard?"}]
response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)
while response.stop_reason == "tool_use":
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type != "tool_use":
continue
try:
shelf = find_book(**block.input)
result = {"type": "tool_result", "tool_use_id": block.id, "content": shelf}
except LookupError as error:
result = {
"type": "tool_result",
"tool_use_id": block.id,
"content": str(error),
"is_error": True,
}
print(f"Tool: {block.name}({block.input}) sent back {result['content']!r}")
results.append(result)
messages.append({"role": "user", "content": results})
response = client.messages.create(
model="claude-opus-5-5", max_tokens=1024, tools=tools, messages=messages
)
print("Claude:", response.content[-1].text)

Step 4: Run It
uv run --env-file .env tool_error.py
Tool: find_book({'title': 'The Silent Orchard'}) sent back "There's no book called 'The Silent Orchard' in the catalogue."
Tool: find_book({'title': 'Silent Orchard'}) sent back "There's no book called 'Silent Orchard' in the catalogue."
Claude: I couldn't find *The Silent Orchard* in the library's catalogue. I also searched for "Silent Orchard" without "The," and that didn't turn up anything either.
Some possible reasons:
- **The title might be a little different.** For example, it could be "The Quiet Orchard" or "Silent Orchards."
- **The library might not have it.** If so, the staff may be able to order it or get it from another library.
If you know the author or remember any other part of the title, I can search again.

The first call failed, and Claude read the error. Then it did what Anthropic's documentation says it might: it called the tool again, this time without "The". When that failed too, it stopped and told the user what it had tried, instead of making up a shelf. The * and ** marks are Markdown: Claude formats replies unless you ask for plain text.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Letting the tool's exception escape the loop | The script stops with a traceback, and Claude never hears about the failure | Catch it and send a tool_result with "is_error": True |
| Skipping the result of the call that failed | 400: `tool_use` ids were found without `tool_result` blocks immediately after | Send a result for every call, failed or not |
A vague message such as "failed" | Claude can't tell what went wrong or what to try next | Say what went wrong, as find_book does |
| A loop with no limit | Claude may keep retrying | Limit the retries, as Anthropic's documentation advises, for example with a counter |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Claude calls the same tool several times in a row | The earlier calls failed and Claude is trying again | Expected; read the errors you sent back, and limit the rounds |
The script stops with a LookupError traceback | The exception wasn't caught inside the loop | Wrap the tool call in try and except |
FAQ
Should I send a stack trace as the error?
No. Send a short message Claude can act on. Anthropic's tip is to write "instructive error messages" that say what went wrong and what Claude should try next.
What if Claude's call itself is invalid, like a missing argument?
That's a failure too: send it back with is_error. To stop such calls from happening at all, Anthropic's documentation points to strict tool use, "strict": True on the tool definition.
Does is_error cost anything extra?
No. The error message is input like any other text, but every retry is another request.
Conclusion
Catching LookupError and sending its message back with "is_error": True kept the loop going. Claude read the error, tried the title without "The", and when that failed too, told the user what it had tried instead of guessing.
Additional Resources
- Handle tool calls — handling errors with
is_error, and writing error messages. - Tool use with Claude — how the tool loop works.
