# How does a LangChain agent handle a tool error?

By default it doesn't: in langchain 1.5.0, an exception that escapes a tool stops the run. The tool node `create_agent` builds uses a default handler that sends only invalid arguments and unknown tool names back to the model as a message.

Two built-in middleware change that. `ToolErrorMiddleware` calls your `on_error` function with each exception. Return text and it becomes an error message for the model; return `None` and the exception propagates. It never retries. `ToolRetryMiddleware` does retry, twice after the first attempt by default, with exponential backoff. When the retries run out it returns an error message to the model, or re-raises if you set `on_failure="error"`.

Once a failure becomes a message, the run can finish without a crash, so a clean run says little. What matters is [what the agent does after the error](/answers/tool-calling/when-a-tool-call-fails-does-an-agent-retry-it-or-try-something-else). The tool node is [the one LangGraph ships](/answers/langgraph-evals/does-langgraph-stop-the-run-when-a-tool-raises-an-error), so its default is the same.

---

Published: 2026-11-13

Sources:
- langchain 1.5.0, agents/middleware/tool_error.py and tool_retry.py (source at commit 980e4a8): https://github.com/langchain-ai/langchain/tree/master/libs/langchain_v1/langchain/agents/middleware (fetched 2026-11-13)
- langgraph-prebuilt 1.1.1, tool_node.py (the default handler is the same at commit 3183e90): https://github.com/langchain-ai/langgraph/blob/main/libs/prebuilt/langgraph/prebuilt/tool_node.py (fetched 2026-11-13)
- LangChain docs: Built-in middleware: https://docs.langchain.com/oss/python/langchain/middleware/built-in (fetched 2026-11-13)

Source: https://tessary.ai/answers/langchain-evals/how-does-a-langchain-agent-handle-a-tool-error
More on LangChain evals: https://tessary.ai/answers/langchain-evals
From Tessary, agent reliability for AI agents in production: https://tessary.ai
