Skip to content

Conversation

@williamhrs
Copy link

@williamhrs williamhrs commented Oct 1, 2025

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 769914b. This will update automatically on new commits. Configure here.

Moves string=[] initialization outside the if block to prevent
UnboundLocalError when API response lacks 'web' key.
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.

1 participant