Fix ToolUsage bare raise for non-dict arguments#6457
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughFixed the non-dict tool-argument path in ChangesToolUsageError fix
Related Issues: #6430 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/crewai/src/crewai/tools/tool_usage.py (1)
838-859: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFix confirmed correct; minor duplication remains.
The fix at Line 853 correctly replaces the bare
raise(which would have hitRuntimeError: No active exception to reraisesince this branch is outside theexceptblock) with an explicitToolUsageError. This matches the localizedtool_arguments_errormessage used elsewhere in this file.Minor note: the same
ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}")construction is now duplicated three times in this function (lines 849, 853, 854). Consider hoisting it into a local variable for readability.♻️ Optional simplification
if not isinstance(arguments, dict): + error = ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}") if raise_error: - raise ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}") - return ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}") + raise error + return error🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/crewai/src/crewai/tools/tool_usage.py` around lines 838 - 859, The `_original_tool_calling` method now has the same `ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}")` repeated in multiple branches, which adds unnecessary duplication. Refactor this method by defining the localized tool-arguments error once inside `_original_tool_calling` and reuse it in both the `except` path and the `not isinstance(arguments, dict)` path, while keeping the explicit `ToolUsageError` behavior in `tool_usage.py`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lib/crewai/src/crewai/tools/tool_usage.py`:
- Around line 838-859: The `_original_tool_calling` method now has the same
`ToolUsageError(f"{I18N_DEFAULT.errors('tool_arguments_error')}")` repeated in
multiple branches, which adds unnecessary duplication. Refactor this method by
defining the localized tool-arguments error once inside `_original_tool_calling`
and reuse it in both the `except` path and the `not isinstance(arguments, dict)`
path, while keeping the explicit `ToolUsageError` behavior in `tool_usage.py`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6a129971-2ddb-46e0-838d-722ea40d93dc
📒 Files selected for processing (2)
lib/crewai/src/crewai/tools/tool_usage.pylib/crewai/tests/tools/test_tool_usage.py
Summary
ToolUsage._original_tool_callingwithToolUsageErrorfor non-dict arguments.raise_error=Truepath.Fixes #6430
Tests
./.venv/Scripts/python.exe -m pytest lib/crewai/tests/tools/test_tool_usage.py::test_original_tool_calling_raises_tool_usage_error_for_non_dict_arguments -q./.venv/Scripts/ruff.exe check lib/crewai/src/crewai/tools/tool_usage.py --select PLE0704Note: the full
test_tool_usage.pyfile has 5 existing failures on Windows becausepytest-recordingdisables socket creation for the event bus; the new regression test passes.