fix(tools): raise ToolUsageError instead of bare raise on non-dict args#6486
Open
HumphreySun98 wants to merge 1 commit into
Open
fix(tools): raise ToolUsageError instead of bare raise on non-dict args#6486HumphreySun98 wants to merge 1 commit into
HumphreySun98 wants to merge 1 commit into
Conversation
_original_tool_calling had a bare `raise` on the `not isinstance(arguments, dict)` path, which is outside the preceding try/except — so with raise_error=True it fails with "RuntimeError: No active exception to re-raise" instead of surfacing the intended tool-arguments error. Raise the ToolUsageError explicitly. Fixes crewAIInc#6430 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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 (2)
📝 WalkthroughWalkthroughFixed a bare ChangesBare raise fix and tests
🚥 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ToolUsage._original_tool_callinghas a bareraiseon the non-dict path, which sits outside the precedingtry/except:_tool_calling()calls this withraise_error=True, so if_validate_tool_inputever returns a non-dict, the bareraisefails withRuntimeError: No active exception to re-raise— masking the intended tool-arguments error. It's a latent landmine today (that helper currently always returns a dict or raises), but it's still incorrect.Fix
Raise the intended
ToolUsageErrorexplicitly:The bare
raiseat the earlier site (insideexcept) is correct and left unchanged.Tests
Added two tests in
test_tool_usage.py(mock_validate_tool_input→ non-dict):raise_error=TrueraisesToolUsageError(notRuntimeError), andraise_error=Falsereturns aToolUsageError. Verified failing-without/passing-with the fix; fulltest_tool_usage.py(30) green;ruff+mypyclean.Fixes #6430
This PR was authored with Claude Code. Per
CONTRIBUTING.md, AI-generated contributions require thellm-generatedlabel — I don't have triage permission to set it, so could a maintainer please add it? 🤖 Generated with Claude Code