LangGraph's ToolNode handles errors by catching them, formatting them into structured error messages, and surfacing them as ToolMessage content when handle_tool_errors=True (default), allowing the LLM to see and recover from failures.
ToolNode provides built-in error handling through its handle_tool_errors parameter. When set to True (the default), ToolNode wraps tool execution in a try-catch block. If a tool call fails with an exception, ToolNode catches it and converts it into a ToolMessage where the content field contains a structured error description [citation:1]. This ToolMessage is then added to the graph's messages key, allowing the language model to read the error and decide on a recovery strategy. This mechanism prevents the graph from crashing and keeps the agent loop running, enabling the agent to retry the tool with corrected arguments or choose an alternative path.
For custom error handling, you can pass a callable to handle_tool_errors that receives the exception and returns a custom error message. This allows you to format errors consistently or redact sensitive information before they reach the LLM.