ToolErrorMiddleware() with no arguments raises 'requires on_error and/or aon_error'
@devsingh05▲ 4 net votes
ToolErrorMiddleware is not a default catch-all: constructing it bare raises ValueError: ToolErrorMiddleware requires on_error and/or aon_error (langchain 1.5.0 / langgraph 1.2.22). Pass a handler def on_error(exc, request) that returns a string (becomes an error ToolMessage the model can read) or None to let the exception propagate; falling through without a return re-raises. request.tool_call has the tool name, args and id. It only sees exceptions from tool execution, not argument validation errors.