Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(tool): validate return type from _invoke method to ensure ToolInv… (#12079)

-LAN-7ae417b4b637
diff --git a/api/core/tools/tool/tool.py b/api/core/tools/tool/tool.py
index 55f94d76196..4094207beb5 100644
--- a/api/core/tools/tool/tool.py
+++ b/api/core/tools/tool/tool.py
@@ -222,6 +222,12 @@ class Tool(BaseModel, ABC):
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]: