CLAUDE LABJP
FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as OctoberFORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Articles/API & SDK
API & SDK/2026-05-05Intermediate

Let Claude Diagnose Its Own Tool Errors — Building a Self-Correction Loop with the Anthropic API

Learn how to handle Tool Use failures gracefully by feeding error details back to Claude using the is_error flag, enabling self-diagnosis and automatic retry. Includes working Python code and production antipatterns to avoid.

claude-api81tool-use22error-handling11python22api-sdk13agentic2

Premium Article

If you've spent any time building with Claude's Tool Use API, you've hit this problem: a tool fails, your agent loop crashes, and the user sees an error that had nothing to do with Claude's reasoning — just a transient network hiccup or a malformed input parameter.

The standard fix is a try-except with a hardcoded retry. But there's a better approach: let Claude itself diagnose the error and decide how to fix it. Once I switched to this pattern, the reliability of my agent implementations improved noticeably.

Assume Tools Will Fail

Most implementations treat tool execution as if it will always succeed:

# Common pattern — no error handling
result = execute_tool(tool_name, tool_input)
messages.append({
    "role": "user",
    "content": [{"type": "tool_result", "tool_use_id": id, "content": str(result)}]
})

When execute_tool raises an exception, the entire agent loop stops. A temporary 503 from an external API becomes a failed request for the user.

In production, tool failure rates are higher than you'd expect. Agents that integrate external APIs typically see 0.5–2% failure rates per month. At scale, that's not acceptable to silently crash.

The is_error Flag — Giving Claude Feedback

The Anthropic API's tool_result message type has an is_error field. Set it to true, and Claude understands that the tool call failed.

{
    "type": "tool_result",
    "tool_use_id": block.id,
    "is_error": True,
    "content": "Error details here..."
}

What you put in content matters enormously. A bare "Error: 500" gives Claude nothing to work with. But a message that explains what failed, what input was used, and what might fix it gives Claude enough context to self-correct.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
How to classify tool failures into input, transient, and structural errors and route each to self-correction or an immediate abort
Avoiding 400s by pairing tool_use with tool_result, plus keeping conversation history from bloating during error loops
Choosing exit conditions and retry strategies for prototypes, user-facing production, and batch pipelines
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API & SDK2026-05-05
Building a 'Think-and-Search' AI Agent — Claude API Extended Thinking × Tool Use
A deep dive into combining Claude API Extended Thinking and Tool Use. Covers frequent errors, a complete research agent implementation in Python, plus cost estimation, timeout design, and error recovery for production use.
API & SDK2026-05-22
Why tool_result could not be submitted Keeps Coming Back, and How to Build a Recovery Handler That Actually Holds
Run a Claude agent long enough and one day it starts: 'tool_result could not be submitted', back to back, and retries change nothing. The error message hides four completely different root causes. Here is what I learned debugging this across the six auto-publishing pipelines I run as an indie developer, with the TypeScript recovery handler I now ship in production.
API & SDK2026-05-16
Debugging Claude API Tool Use Schema Errors: 3 Patterns I've Hit and How to Fix Them
A practical guide to diagnosing Claude API Tool Use errors—from schema definition mistakes to invalid_tool_use blocks and Claude ignoring your tools entirely. Based on real implementation experience.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →