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: 619656a1-bedd-47db-8cb4-7ab55b8762ce

📥 Commits

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

📒 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/tests/tools/test_tool_usage.py
  • lib/crewai/src/crewai/tools/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 clearly describes the core fix to invalid tool arguments raising ToolUsageError.
Description check ✅ Passed The description matches the changes and explains the fix, regression test, and validation steps.
Linked Issues check ✅ Passed The changes implement #6430 by replacing the bare raise with ToolUsageError and adding regression coverage.
Out of Scope Changes check ✅ Passed No unrelated code changes are introduced beyond the tool usage fix and its test.
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 2 times, most recently from d336ec8 to a6c62a5 Compare July 7, 2026 16:31
@sjsjsjjs534 sjsjsjjs534 force-pushed the codex/fix-tool-usage-bare-raise branch from a6c62a5 to add5c32 Compare July 8, 2026 16:25
@ErenAta16

Copy link
Copy Markdown

Same one-line fix as #6486, #6512, #6511, #6499, #6495 — that is now six open PRs (this one included) independently fixing the same bare-raise-outside-except bug in _original_tool_calling (raises RuntimeError: No active exception to reraise instead of the intended ToolUsageError, confirmed by reproducing it standalone). Left a fuller comparison and picked #6486 as the cleanest of the batch (constructs the error once, reuses it for both branches, has an explanatory comment) in that thread. Flagging the duplication here too so only one of the six lands.

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

2 participants