Skip to content

GoogleModel drops WebSearchTool.blocked_domains, though google-genai now exposes GoogleSearch.exclude_domains #8218

Description

@hotheartguy

Summary

GoogleModel discards WebSearchTool.blocked_domains. The google-genai SDK now
has a field for it — GoogleSearch.exclude_domains — so the mapping is available
but not wired up.

This is the GoogleModel row of the matrix in #6156. That issue was closed after
the Groq row was fixed (_get_native_tools now builds search_settings with
include_domains / exclude_domains); the Google row was left as-is.

Reproduction

Network-free — a MockTransport captures the outgoing body, so no API key is needed.
Verified on pydantic-ai-slim[google]==2.40.0 / google-genai==2.22.0.

import asyncio, json, httpx
from google.genai import Client
from google.genai.types import HttpOptions
from pydantic_ai import WebSearchTool
from pydantic_ai.messages import ModelRequest, UserPromptPart
from pydantic_ai.models import ModelRequestParameters
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google import GoogleProvider

captured = {}
CANNED = {
    'candidates': [{'content': {'role': 'model', 'parts': [{'text': 'ok'}]}, 'finishReason': 'STOP'}],
    'usageMetadata': {'promptTokenCount': 1, 'candidatesTokenCount': 1, 'totalTokenCount': 2},
    'modelVersion': 'gemini-3.7-flash',
}

async def handler(request: httpx.Request) -> httpx.Response:
    captured['body'] = json.loads(request.content)
    return httpx.Response(200, json=CANNED)

async def main():
    client = Client(
        api_key='not-a-real-key',
        http_options=HttpOptions(async_client_args={'transport': httpx.MockTransport(handler)}),
    )
    model = GoogleModel('gemini-3.7-flash', provider=GoogleProvider(client=client))
    await model.request(
        [ModelRequest(parts=[UserPromptPart(content='hi')])],
        None,
        ModelRequestParameters(native_tools=[WebSearchTool(blocked_domains=['example.com'])]),
    )
    print('sent:', json.dumps(captured['body']['tools']))

asyncio.run(main())

Output:

sent: [{"googleSearch": {}}]

blocked_domains is gone, with no error and no warning.

Cause

models/google.py:744 constructs the tool with no arguments:

if isinstance(tool, WebSearchTool):
    tools.append(ToolDict(google_search=GoogleSearchDict()))

The SDK field exists

>>> from google.genai.types import GoogleSearch
>>> list(GoogleSearch.model_fields)
['search_types', 'blocking_confidence', 'exclude_domains', 'time_range_filter']
>>> GoogleSearch(exclude_domains=['example.com']).model_dump(exclude_none=True)
{'exclude_domains': ['example.com']}

So blocked_domainsexclude_domains is a direct mapping, the same shape as the
Groq fix in #6156.

Suggested fix (sketch)

if isinstance(tool, WebSearchTool):
    google_search = GoogleSearchDict()
    if tool.blocked_domains is not None:
        google_search['exclude_domains'] = tool.blocked_domains
    tools.append(ToolDict(google_search=google_search))

and add Google to the WebSearchTool.blocked_domains docstring's "Supported by" list.

Note allowed_domains has no Google equivalent — GoogleSearch only offers the
exclude side — so that one stays unsupported.

Out of scope (checked, not asking for these)

  • max_uses — documented as ignored ("Other native providers ignore it"), and
    GoogleSearch has no equivalent knob. Working as intended.
  • Vertex + Gemini 3 grounding — the
    include_server_side_tool_invocations parameter is not supported in Vertex AI
    ValueError is already fixed on main by the not self._is_google_cloud guard.
    Mentioned only so it is not re-reported.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    p:4-lowSignal 0-3: low, probably unplanned.pydanty:featureManaged by pydanty dogfooding automation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions