Skip to content

web_search: return an error when the Brave API key is unconfigured#488

Merged
rockfordlhotka merged 1 commit into
mainfrom
fix/web-search-missing-key-error
Jul 12, 2026
Merged

web_search: return an error when the Brave API key is unconfigured#488
rockfordlhotka merged 1 commit into
mainfrom
fix/web-search-missing-key-error

Conversation

@rockfordlhotka

Copy link
Copy Markdown
Member

Problem

When no Brave Search API key is configured, BraveSearchProvider.SearchAsync returned an empty list, and WebSearchToolExecutor mapped Count == 0 to "No results found." with IsError = false. That's indistinguishable from a search that ran and genuinely found nothing — so the agent can't tell the user that web search isn't set up, and just reports "no results."

Noticed while bringing up the docker-compose stack without a BRAVE_API_KEY: web_search is still offered to the model every turn but silently returns nothing.

Change

  • Add WebSearchNotConfiguredException.
  • BraveSearchProvider throws it (with an actionable message naming WebTools:ApiKey and the env var) instead of returning [].
  • WebSearchToolExecutor catches it and returns IsError = true with that message — distinct from both the generic "Search failed: …" path and "No results found.".

Result — the agent now receives, and can relay:

Web search is unavailable because the Brave Search API key is not configured. Set WebTools:ApiKey (config / user secrets) or the BRAVE_API_KEY environment variable.

Tests

  • Updated BraveSearchProviderTests: missing key now asserts ThrowsExactlyAsync<WebSearchNotConfiguredException>.
  • New WebSearchToolExecutorTests case: provider throwing WebSearchNotConfiguredExceptionIsError = true with the actionable message.
  • All 40 RockBot.Tools.Web.Tests pass.

🤖 Generated with Claude Code

Previously BraveSearchProvider returned an empty result list when no API key
was set, which WebSearchToolExecutor reported as "No results found." with
IsError=false. That's indistinguishable from a search that genuinely found
nothing, so the agent couldn't tell the user that web search is simply not
configured.

Introduce WebSearchNotConfiguredException; the provider throws it (with an
actionable message naming WebTools:ApiKey / the env var) instead of returning
empty, and the executor catches it to return IsError=true with that message.
Distinct from both the generic "Search failed" path and "No results found".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rockfordlhotka
rockfordlhotka merged commit 9d94951 into main Jul 12, 2026
2 checks passed
@rockfordlhotka
rockfordlhotka deleted the fix/web-search-missing-key-error branch July 12, 2026 03:55
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