Skip to content

fix: replace bare raise in _original_tool_calling to prevent RuntimeError#6556

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

fix: replace bare raise in _original_tool_calling to prevent RuntimeError#6556
nankingjing wants to merge 1 commit into
crewAIInc:mainfrom
nankingjing:fix/bare-raise-tool-usage

Conversation

@nankingjing

Copy link
Copy Markdown

Fixes #6430

Bare raise in ToolUsage._original_tool_calling() causes RuntimeError: No active exception to re-raise when the non-dict-arguments path is reached with raise_error=True, because no exception is active on that path (the preceding try/except completed normally). This is a latent landmine that triggers when the model struggles with parameter formatting, and it breaks the fallback logic in _tool_calling(), which relies on catching a meaningful exception.

Also flagged by ruff check --select PLE0704.

Fix: Replace the bare raise with raise ToolUsageError(...) using the existing i18n tool_arguments_error message, mirroring the raise_error=False branch.

Test: Added a regression test (test_original_tool_calling_non_dict_arguments_raises_tool_usage_error) that forces _validate_tool_input to return a non-dict and asserts ToolUsageError is raised with raise_error=True (and returned with raise_error=False) instead of a cryptic RuntimeError.

Note: this contribution was made with AI assistance — per CONTRIBUTING.md it needs the llm-generated label, which I can't set myself.

A bare `raise` outside an except block in the non-dict arguments branch
of ToolUsage._original_tool_calling() raises
`RuntimeError: No active exception to re-raise` instead of a meaningful
tool-arguments error. Raise ToolUsageError with the existing i18n
message, mirroring the raise_error=False branch.

Fixes crewAIInc#6430
@coderabbitai

coderabbitai Bot commented Jul 15, 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: abf7530f-6087-4e1e-87b4-b63e1eb857e7

📥 Commits

Reviewing files that changed from the base of the PR and between da9902d and 2931e2f.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/tools/tool_usage.py
  • lib/crewai/tests/tools/test_tool_usage.py

📝 Walkthrough

Walkthrough

ToolUsage._original_tool_calling now raises ToolUsageError with the existing localized message when validated tool arguments are not dictionaries. A regression test covers both raising and returned-error behavior.

Changes

Tool argument error handling

Layer / File(s) Summary
Raise ToolUsageError for invalid arguments
lib/crewai/src/crewai/tools/tool_usage.py, lib/crewai/tests/tools/test_tool_usage.py
Non-dictionary validated arguments now raise the localized ToolUsageError when requested, while tests verify both raise and return paths for the error.

Suggested reviewers: greysonlalonde

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: replacing the bare raise in _original_tool_calling to avoid a RuntimeError.
Description check ✅ Passed The description is directly about the same bug fix and regression test in ToolUsage._original_tool_calling.
Linked Issues check ✅ Passed The code change and test satisfy #6430 by raising ToolUsageError for non-dict arguments and avoiding the bare raise.
Out of Scope Changes check ✅ Passed The diff stays focused on the bug fix and its regression test, with no clear unrelated code 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.

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