{"record":{"id":"965339d7b61af1cc","repo":"langchain-ai/langgraph","slug":"tool-name-returned-a-list-with-invalid-element-t","errorCode":null,"errorMessage":"Tool {name} returned a list with invalid element types: expected all Command or ToolMessage","messagePattern":"Tool (.+?) returned a list with invalid element types: expected all Command or ToolMessage","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/prebuilt/langgraph/prebuilt/tool_node.py","lineNumber":1451,"sourceCode":"        self,\n        response: Any,\n        tool_call: ToolCall,\n        input_type: Literal[\"list\", \"dict\", \"tool_calls\"],\n    ) -> ToolMessage | Command | list[Command | ToolMessage]:\n        \"\"\"Validate and normalize a tool's raw return value.\"\"\"\n        if isinstance(response, Command):\n            return self._validate_tool_command(response, tool_call, input_type)\n        if isinstance(response, ToolMessage):\n            response.content = cast(\"str | list\", msg_content_output(response.content))\n            return response\n        if isinstance(response, list):\n            if all(isinstance(r, (Command, ToolMessage)) for r in response):\n                return self._validate_tool_command_list(response, tool_call, input_type)\n            msg = (\n                f\"Tool {tool_call['name']} returned a list with invalid element \"\n                \"types: expected all Command or ToolMessage\"\n            )\n            raise TypeError(msg)\n        msg = f\"Tool {tool_call['name']} returned unexpected type: {type(response)}\"\n        raise TypeError(msg)\n\n    def _validate_tool_command_list(\n        self,\n        response: list[Command | ToolMessage],\n        tool_call: ToolCall,\n        input_type: Literal[\"list\", \"dict\", \"tool_calls\"],\n    ) -> list[Command | ToolMessage]:\n        \"\"\"Validate a list of Command/ToolMessage returned by a single tool call.\n\n        Requires exactly one terminating ToolMessage (matching the outer tool_call_id)\n        across the list — either as a top-level element or nested in a\n        Command.update[\"messages\"].\n        \"\"\"\n        expected_id = tool_call[\"id\"]\n\n        terminator_count = 0","sourceCodeStart":1433,"sourceCodeEnd":1469,"githubUrl":"https://github.com/langchain-ai/langgraph/blob/38031739e551638e373fb553453256c23feeb41f/libs/prebuilt/langgraph/prebuilt/tool_node.py#L1433-L1469","documentation":"Error \"Tool {name} returned a list with invalid element types: expected all Command or ToolMessage\" thrown in langchain-ai/langgraph.","triggerScenarios":"Thrown at libs/prebuilt/langgraph/prebuilt/tool_node.py:1451 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"}