crewAI-tools
crewAI-tools copied to clipboard
fix: initialize string list before conditional in BraveSearchTool
Problem
Fixes UnboundLocalError that occurs when Brave Search API returns responses without a 'web' key.
Solution
Moves string = [] initialization outside the conditional block (before line 95), ensuring the variable is always defined before being referenced on line 112.
Testing
- All existing tests pass with valid API key
- Follows standard Python practice for preventing UnboundLocalError
- No breaking changes to existing functionality
Related
This defensive fix prevents crashes on empty/malformed API responses, allowing graceful error handling.
[!NOTE] Initialize
stringbefore the"web" in resultscheck to ensure it's defined even whenwebis absent.
- BraveSearchTool (
crewai_tools/tools/brave_search_tool/brave_search_tool.py):
- Initialize
string = []before checking forresults["web"]and remove duplicate init inside the block, preventingUnboundLocalErrorwhenwebis missing.Written by Cursor Bugbot for commit 769914b192e8be2621cf82d56b195e1a26b70ec9. This will update automatically on new commits. Configure here.