Skip to content

fix(grok): stop rejecting hosted web search domain and location filters - #125

Open
AlexanderKugel wants to merge 1 commit into
raine:mainfrom
AlexanderKugel:fix/grok-search-constraints
Open

fix(grok): stop rejecting hosted web search domain and location filters#125
AlexanderKugel wants to merge 1 commit into
raine:mainfrom
AlexanderKugel:fix/grok-search-constraints

Conversation

@AlexanderKugel

Copy link
Copy Markdown
Contributor

Fixes #123.

Problem

Claude Code can declare Anthropic hosted web search with allowed_domains, blocked_domains, or user_location. Grok's hosted web_search has no equivalent fields, so the proxy returns HTTP 400 without calling Grok.

Claude Code surfaces that 400 to the model as an error tool_result. The model then retries the same search without the filter, and the retry is accepted and runs unrestricted. The rejection therefore costs an extra round and the caller's constraint is lost anyway.

Change

CCP_SEARCH_CONSTRAINTS selects the behaviour for providers that cannot enforce these fields:

Value Behaviour
soft (default) Drop the fields and turn each one into an instruction appended to the upstream request's instructions field.
warning Drop the fields, log a warning, send the search unrestricted.
hard Keep the current HTTP 400.

hard preserves today's behaviour for anyone who wants it. The 400 message now names every unsupported field in the request instead of only the first one found.

max_uses stays dropped, as before.

Example of the appended instruction:

You are only allowed to search allowed_domains=["langchain.com","docs.langchain.com","blog.langchain.com"].

Values are copied verbatim from the caller. The proxy does not parse them.

Why soft is the default

Measured with 10 live searches per group, same query, three allowed domains:

Group Runs Total [in-domain, off-domain] In-domain share
soft 10/10 [161, 0] 100.0%
no domain list 10/10 [147, 210] 41.2%

Grok applies the instruction by adding site: filters to its own search queries. soft is a bias, not enforcement; the model can ignore it.

Notes

Claude Code can declare Anthropic hosted web search with allowed_domains,
blocked_domains, or user_location. Grok's hosted web_search has no equivalent
fields, so the proxy returned HTTP 400 without calling Grok.

Claude Code surfaces that 400 to the model as an error tool_result, and the
model retries the same search without the filter. The retry is accepted and
runs unrestricted, so the rejection costs an extra round and does not preserve
the caller's constraint.

CCP_SEARCH_CONSTRAINTS selects the behaviour:

  soft    (default) drop the fields and turn each one into an instruction in
          the upstream request's instructions field
  warning drop the fields, log a warning, send the search unrestricted
  hard    keep the HTTP 400

Measured over 10 live searches with three allowed domains, soft returned 161
in-domain sources and 0 off-domain. The same query with no domain list returned
147 in-domain and 210 off-domain. Grok applies the instruction by adding site:
filters to its own queries. soft is a bias, not enforcement.

max_uses stays dropped, as before.
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.

Grok hosted web search constraints cause a proxy 400, after which Claude Code retries without them

1 participant