microsoft/autogen · error · TypeError
Expected return value of type {self._return_type.__name__},
Error message
Expected return value of type {self._return_type.__name__}, but got {type(return_value).__name__} What it means
Error "Expected return value of type {self._return_type.__name__}, but got {type(return_value).__name__}" thrown in microsoft/autogen.
Source
Thrown at python/packages/autogen-core/src/autogen_core/tools/_base.py:257
call_id (str | None): An optional identifier for the tool call, used for tracing.
Returns:
AsyncGenerator[StreamT | ReturnT, None]: A generator yielding results from the tool's :meth:`run_stream` method.
"""
return_value: ReturnT | StreamT | None = None
with trace_tool_span(
tool_name=self._name,
tool_description=self._description,
tool_call_id=call_id,
):
# Execute the tool's run_stream method
async for result in self.run_stream(self._args_type.model_validate(args), cancellation_token):
return_value = result
yield result
assert return_value is not None, "The tool must yield a final return value at the end of the stream."
if not isinstance(return_value, self._return_type):
raise TypeError(
f"Expected return value of type {self._return_type.__name__}, but got {type(return_value).__name__}"
)
# Log the tool call event
event = ToolCallEvent(
tool_name=self.name,
arguments=dict(args), # Using the raw args passed to run_json
result=self.return_value_as_string(return_value),
)
logger.info(event)
class BaseToolWithState(BaseTool[ArgsT, ReturnT], ABC, Generic[ArgsT, ReturnT, StateT], ComponentBase[BaseModel]):
def __init__(
self,
args_type: Type[ArgsT],
return_type: Type[ReturnT],
state_type: Type[StateT],View on GitHub (pinned to 027ecf0a37)
Solutions
- Return a value matching the tool's declared return type
Example fix
Cast/convert the return value to the declared type
When it happens
Trigger: Thrown at python/packages/autogen-core/src/autogen_core/tools/_base.py:257 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/53b8e466cf80c541.
Report an issue: GitHub.