{"record":{"id":"53b8e466cf80c541","repo":"microsoft/autogen","slug":"expected-return-value-of-type-self-return-type","errorCode":null,"errorMessage":"Expected return value of type {self._return_type.__name__}, but got {type(return_value).__name__}","messagePattern":"Expected return value of type (.+?), but got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/tools/_base.py","lineNumber":257,"sourceCode":"            call_id (str | None): An optional identifier for the tool call, used for tracing.\n\n        Returns:\n            AsyncGenerator[StreamT | ReturnT, None]: A generator yielding results from the tool's :meth:`run_stream` method.\n        \"\"\"\n        return_value: ReturnT | StreamT | None = None\n        with trace_tool_span(\n            tool_name=self._name,\n            tool_description=self._description,\n            tool_call_id=call_id,\n        ):\n            # Execute the tool's run_stream method\n            async for result in self.run_stream(self._args_type.model_validate(args), cancellation_token):\n                return_value = result\n                yield result\n\n        assert return_value is not None, \"The tool must yield a final return value at the end of the stream.\"\n        if not isinstance(return_value, self._return_type):\n            raise TypeError(\n                f\"Expected return value of type {self._return_type.__name__}, but got {type(return_value).__name__}\"\n            )\n\n        # Log the tool call event\n        event = ToolCallEvent(\n            tool_name=self.name,\n            arguments=dict(args),  # Using the raw args passed to run_json\n            result=self.return_value_as_string(return_value),\n        )\n        logger.info(event)\n\n\nclass BaseToolWithState(BaseTool[ArgsT, ReturnT], ABC, Generic[ArgsT, ReturnT, StateT], ComponentBase[BaseModel]):\n    def __init__(\n        self,\n        args_type: Type[ArgsT],\n        return_type: Type[ReturnT],\n        state_type: Type[StateT],","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/tools/_base.py#L239-L275","documentation":"Error \"Expected return value of type {self._return_type.__name__}, but got {type(return_value).__name__}\" thrown in microsoft/autogen.","triggerScenarios":"Thrown at python/packages/autogen-core/src/autogen_core/tools/_base.py:257 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Return a value matching the tool's declared return type"],"exampleFix":"Cast/convert the return value to the declared type","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}