crewAI-tools icon indicating copy to clipboard operation
crewAI-tools copied to clipboard

fix: initialize string list before conditional in BraveSearchTool

Open williamhrs opened this issue 5 months ago • 0 comments

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 string before the "web" in results check to ensure it's defined even when web is absent.

  • BraveSearchTool (crewai_tools/tools/brave_search_tool/brave_search_tool.py):
    • Initialize string = [] before checking for results["web"] and remove duplicate init inside the block, preventing UnboundLocalError when web is missing.

Written by Cursor Bugbot for commit 769914b192e8be2621cf82d56b195e1a26b70ec9. This will update automatically on new commits. Configure here.

williamhrs avatar Oct 01 '25 02:10 williamhrs