From 3c41d3aa60a20835c9891720609a7169fa7bbc7a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 13:26:46 +0000 Subject: [PATCH] fix: raise ValueError for missing required arguments Co-Authored-By: Joe Moura --- src/crewai/tools/tool_usage.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/crewai/tools/tool_usage.py b/src/crewai/tools/tool_usage.py index b27b0e094..3d3fe3a14 100644 --- a/src/crewai/tools/tool_usage.py +++ b/src/crewai/tools/tool_usage.py @@ -186,22 +186,24 @@ class ToolUsage: ) self.task.increment_delegations(coworker) - if calling.arguments: - try: - acceptable_args = tool.args_schema.model_json_schema()[ - "properties" - ].keys() # type: ignore - arguments = { - k: v - for k, v in calling.arguments.items() - if k in acceptable_args - } - result = tool.invoke(input=arguments) - except Exception: - arguments = calling.arguments - result = tool.invoke(input=arguments) - else: - result = tool.invoke(input={}) + if not calling.arguments: + raise ValueError("Tool arguments cannot be empty") + + try: + acceptable_args = tool.args_schema.model_json_schema()[ + "properties" + ].keys() # type: ignore + arguments = { + k: v + for k, v in calling.arguments.items() + if k in acceptable_args + } + result = tool.invoke(input=arguments) + except Exception as e: + if isinstance(e, TypeError) and "missing 1 required positional argument" in str(e): + raise ValueError("Required arguments missing for tool") + arguments = calling.arguments + result = tool.invoke(input=arguments) except Exception as e: self.on_tool_error(tool=tool, tool_calling=calling, e=e) self._run_attempts += 1