{"record":{"id":"ede89a261a431e9a","repo":"langchain-ai/langgraph","slug":"last-message-is-not-an-aimessage","errorCode":null,"errorMessage":"Last message is not an AIMessage","messagePattern":"Last message is not an AIMessage","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/prebuilt/langgraph/prebuilt/tool_validator.py","lineNumber":181,"sourceCode":"            else:\n                raise ValueError(\n                    f\"Unsupported input to ValidationNode. Expected BaseModel, tool or function. Got: {type(schema)}.\"\n                )\n\n    def _get_message(\n        self, input: list[AnyMessage] | dict[str, Any]\n    ) -> tuple[str, AIMessage]:\n        \"\"\"Extract the last AIMessage from the input.\"\"\"\n        if isinstance(input, list):\n            output_type = \"list\"\n            messages: list = input\n        elif messages := input.get(\"messages\", []):\n            output_type = \"dict\"\n        else:\n            raise ValueError(\"No message found in input\")\n        message: AnyMessage = messages[-1]\n        if not isinstance(message, AIMessage):\n            raise ValueError(\"Last message is not an AIMessage\")\n        return output_type, message\n\n    def _func(\n        self, input: list[AnyMessage] | dict[str, Any], config: RunnableConfig\n    ) -> Any:\n        \"\"\"Validate and run tool calls synchronously.\"\"\"\n        output_type, message = self._get_message(input)\n\n        def run_one(call: ToolCall) -> ToolMessage:\n            schema = self.schemas_by_name[call[\"name\"]]\n            try:\n                if issubclass(schema, BaseModel):\n                    output = schema.model_validate(call[\"args\"])\n                    content = output.model_dump_json()\n                elif issubclass(schema, BaseModelV1):\n                    output = schema.validate(call[\"args\"])\n                    content = output.json()\n                else:","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/langchain-ai/langgraph/blob/38031739e551638e373fb553453256c23feeb41f/libs/prebuilt/langgraph/prebuilt/tool_validator.py#L163-L199","documentation":"Error \"Last message is not an AIMessage\" thrown in langchain-ai/langgraph.","triggerScenarios":"Thrown at libs/prebuilt/langgraph/prebuilt/tool_validator.py:181 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"}