Skip to content

feat(web): add exclude_domains to web_search for search benchmarks - #117

Open
nan-wang wants to merge 1 commit into
ArtificialAnalysis:mainfrom
nan-wang:feat/web-search-exclude-domains
Open

nan-wang wants to merge 1 commit into
ArtificialAnalysis:mainfrom
nan-wang:feat/web-search-exclude-domains

Conversation

@nan-wang

Copy link
Copy Markdown

Summary

Search benchmarks need some sites kept out of the agent's search results, usually the site hosting the benchmark's questions and answers. This adds that option to web_search:

WebToolProvider(exclude_domains=["huggingface.co", "github.com"])

or, so it also applies to default_tools() without code changes:

export WEB_SEARCH_EXCLUDE_DOMAINS="huggingface.co,github.com"
  • Excluding a domain also excludes its subdomains (huggingface.co covers discuss.huggingface.co).
  • Entries may be bare domains or URLs, and a leading *. is accepted. Anything that is not a hostname raises ValueError.
  • An explicit exclude_domains replaces the env var; exclude_domains=[] turns it off.
  • Only web_search is filtered. fetch_web_page can still open a URL on an excluded domain (see below).

How it maps to Brave

Brave Search has no exclude_domains parameter. The Goggles docs say domains are removed with $discard,site=<domain> rules, sent inline in the goggles query parameter, one rule per line. The tool sends one inline Goggle with a rule per domain.

Brave does not say whether site= matches subdomains. So the tool also drops any returned result whose host is an excluded domain or one of its subdomains, and counts those in the new WebSearchMetadata.results_excluded. A search can therefore return fewer than 5 results. A non-zero results_excluded also shows when the server-side rule let something through.

Domains are written into Goggle rules, so entries are limited to hostname characters. Otherwise an entry like "a.com\n$discard" would inject a generic rule that discards every result.

Naming in other search APIs

I checked the docs of the other common search APIs. The feature is the same everywhere but the parameter name differs. The table is also in docs/api/tools/web.md as the mapping to use when another provider is added:

Provider Parameter
Brave Search goggles with $discard,site=<domain> rules
Tavily exclude_domains
Exa excludeDomains
Parallel source_policy.exclude_domains
Perplexity Search search_domain_filter, each domain prefixed with -
Anthropic web search tool blocked_domains
OpenAI web search tool filters.blocked_domains
Vertex AI Google Search grounding exclude_domains

Not in this PR

  • fetch_web_page is not restricted. An agent that already knows a URL on an excluded domain can still open it. Blocking fetches as well is a small follow-up if benchmark runs need it.

Testing

  • New tests in tests/test_web_search.py (mocked Brave transport): the Goggle request parameter, normalization and de-duplication, client-side removal of subdomain matches (and no false matches on nothuggingface.co or on the URL path), metadata aggregation, rejection of invalid or injecting entries, the env var fallback, and [] overriding the env var.
  • pytest -m "not docker and not e2b and not browser" (without the model-speed and MCP smoke tests): 382 passed. ruff format --check, ruff check and ty check are clean.
  • Not tested against the live Brave API, since no key was available. A quick check with a real key that goggles=$discard,site=... removes the domain would be worthwhile.

🤖 Generated with Claude Code

WebToolProvider(exclude_domains=[...]) removes the listed domains, subdomains
included, from web_search results. Without the argument the comma-separated
WEB_SEARCH_EXCLUDE_DOMAINS environment variable is used, so default_tools()
benchmark runs can turn it on without code changes.

Brave has no exclude_domains parameter, so the domains are sent as one inline
Goggle with a `$discard,site=<domain>` rule each. Brave does not document
whether site= covers subdomains, so results from an excluded host are also
dropped client-side and counted in WebSearchMetadata.results_excluded.
Entries are restricted to hostname characters so they cannot inject Goggle
rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant