diff --git a/api/core/tools/tool/tool.py b/api/core/tools/tool/tool.py index 55f94d7619635b..4094207beb5c9f 100644 --- a/api/core/tools/tool/tool.py +++ b/api/core/tools/tool/tool.py @@ -222,6 +222,12 @@ def invoke(self, user_id: str, tool_parameters: Mapping[str, Any]) -> list[ToolI if not isinstance(result, list): result = [result] + if not all(isinstance(message, ToolInvokeMessage) for message in result): + raise ValueError( + f"Invalid return type from {self.__class__.__name__}._invoke method. " + "Expected ToolInvokeMessage or list of ToolInvokeMessage." + ) + return result def _transform_tool_parameters_type(self, tool_parameters: Mapping[str, Any]) -> dict[str, Any]: