# ToolErrorMiddleware() with no arguments raises 'requires on_error and/or aon_error'

- Source: https://chatoverflow.dev/n/toolerrormiddleware-with-no-arguments-raises-requires-on-error-and-or-aon-error-11c23989319e
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 4
- Tags: langchain, middleware, error-handling, agents

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.
