{"record":{"id":"5b18c7d03f954513","repo":"langchain-ai/langgraph","slug":"got-unexpected-type-of-handle-tool-error-expect","errorCode":null,"errorMessage":"Got unexpected type of `handle_tool_error`. Expected bool, str or callable. Received: {flag}","messagePattern":"Got unexpected type of `handle_tool_error`\\. Expected bool, str or callable\\. Received: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/prebuilt/langgraph/prebuilt/tool_node.py","lineNumber":440,"sourceCode":"\n    !!! note\n        The tuple case is handled by the caller through exception type checking,\n        not by this function directly.\n    \"\"\"\n    if isinstance(flag, (bool, tuple)) or (\n        isinstance(flag, type) and issubclass(flag, Exception)\n    ):\n        content = TOOL_CALL_ERROR_TEMPLATE.format(error=repr(e))\n    elif isinstance(flag, str):\n        content = flag\n    elif callable(flag):\n        content = flag(e)  # type: ignore [assignment, call-arg]\n    else:\n        msg = (\n            f\"Got unexpected type of `handle_tool_error`. Expected bool, str \"\n            f\"or callable. Received: {flag}\"\n        )\n        raise ValueError(msg)\n    return content\n\n\ndef _infer_handled_types(handler: Callable[..., str]) -> tuple[type[Exception], ...]:\n    \"\"\"Infer exception types handled by a custom error handler function.\n\n    This function analyzes the type annotations of a custom error handler to determine\n    which exception types it's designed to handle. This enables type-safe error handling\n    where only specific exceptions are caught and processed by the handler.\n\n    Args:\n        handler: A callable that takes an exception and returns an error message string.\n                The first parameter (after self/cls if present) should be type-annotated\n                with the exception type(s) to handle.\n\n    Returns:\n        A tuple of exception types that the handler can process. Returns (Exception,)\n        if no specific type information is available for backward compatibility.","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/langchain-ai/langgraph/blob/38031739e551638e373fb553453256c23feeb41f/libs/prebuilt/langgraph/prebuilt/tool_node.py#L422-L458","documentation":"Error \"Got unexpected type of `handle_tool_error`. Expected bool, str or callable. Received: {flag}\" thrown in langchain-ai/langgraph.","triggerScenarios":"Thrown at libs/prebuilt/langgraph/prebuilt/tool_node.py:440 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"38031739e551638e373fb553453256c23feeb41f","analyzedAt":"2026-08-26T18:02:49.312Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}