Skip to content

fix(tools): raise tool usage error for invalid arguments#6436

Open
sjsjsjjs534 wants to merge 1 commit into
crewAIInc:mainfrom
sjsjsjjs534:codex/fix-tool-usage-bare-raise
Open

fix(tools): raise tool usage error for invalid arguments#6436
sjsjsjjs534 wants to merge 1 commit into
crewAIInc:mainfrom
sjsjsjjs534:codex/fix-tool-usage-bare-raise

Conversation

@sjsjsjjs534

Copy link
Copy Markdown

Summary

  • raise ToolUsageError explicitly when parsed tool arguments are not a dictionary
  • add regression coverage for the raise_error=True path so it no longer falls through to a bare raise

Closes #6430.

Tests

  • UV_CACHE_DIR=/private/tmp/uv-cache-crewai UV_PYTHON_INSTALL_DIR=/private/tmp/uv-python-crewai uv run pytest lib/crewai/tests/tools/test_tool_usage.py::test_original_tool_calling_raises_tool_usage_error_for_non_dict_arguments
  • UV_CACHE_DIR=/private/tmp/uv-cache-crewai UV_PYTHON_INSTALL_DIR=/private/tmp/uv-python-crewai uv run pytest lib/crewai/tests/tools/test_tool_usage.py
  • UV_CACHE_DIR=/private/tmp/uv-cache-crewai UV_PYTHON_INSTALL_DIR=/private/tmp/uv-python-crewai uv run ruff check lib/crewai/src/crewai/tools/tool_usage.py lib/crewai/tests/tools/test_tool_usage.py
  • UV_CACHE_DIR=/private/tmp/uv-cache-crewai UV_PYTHON_INSTALL_DIR=/private/tmp/uv-python-crewai uv run ruff format --check lib/crewai/src/crewai/tools/tool_usage.py lib/crewai/tests/tools/test_tool_usage.py

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 43378801-6319-4a70-ac44-58010e71f96f

📥 Commits

Reviewing files that changed from the base of the PR and between cc5ea28 and d336ec8.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/tools/tool_usage.py
  • lib/crewai/tests/tools/test_tool_usage.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/crewai/src/crewai/tools/tool_usage.py
  • lib/crewai/tests/tools/test_tool_usage.py

📝 Walkthrough

Walkthrough

Fixed ToolUsage._original_tool_calling to raise ToolUsageError for non-dict validated tool input and added a regression test for that branch.

Changes

ToolUsageError raise fix

Layer / File(s) Summary
Raise explicit ToolUsageError and add regression test
lib/crewai/src/crewai/tools/tool_usage.py, lib/crewai/tests/tools/test_tool_usage.py
Constructs a ToolUsageError in the non-dict branch, raises or returns that same instance based on raise_error, and adds a unit test that mocks validation to return a list and checks the error message.

Related Issues: #6430
Suggested Labels: bug, llm-generated

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: raising ToolUsageError for invalid tool arguments.
Description check ✅ Passed The description matches the code changes and regression test added in the pull request.
Linked Issues check ✅ Passed The changes address #6430 by replacing the bare raise with ToolUsageError and adding a regression test.
Out of Scope Changes check ✅ Passed The PR stays scoped to the bug fix and its test, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sjsjsjjs534 sjsjsjjs534 force-pushed the codex/fix-tool-usage-bare-raise branch from cc5ea28 to d336ec8 Compare July 2, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bare raise in ToolUsage._original_tool_calling causes RuntimeError instead of ToolUsageError

1 participant