googleapis / googleapis/python-genai

exclude_domains not converted to excludeDomains for Vertex AI requests

Aperta
#1,965 4 commenti 0 reazioni 1 assegnatario Vedi su GitHub

Nessuno ha ancora preso questa issue.

api: vertex-ai type: bug
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

## Description

When using Google Search grounding with Vertex AI, the `exclude_domains` parameter is not being converted to `excludeDomains` (camelCase) in the API request, causing the parameter to be silently ignored.

## Steps to Reproduce

```python
from google import genai
from google.genai import types

client = genai.Client(vertexai=True)

config = types.GenerateContentConfig(
temperature=0.5,
max_output_tokens=100,
tools=[
types.Tool(
google_search=types.GoogleSearch(
exclude_domains=["example.com"]
)
)
],
)

response = client.models.generate_content(
model="gemini-2.5-flash-lite",
contents="Search the web for something",
config=config,
)
```

## Expected Behavior

The API request should contain:
```json
{
"tools": [{
"googleSearch": {
"excludeDomains": ["example.com"]
}
}]
}
```

## Actual Behavior

The API request contains snake_case which the API ignores:
```json
{
"tools": [{
"googleSearch": {
"exclude_domains": ["example.com"]
}
}]
}
```

The excluded domains are not respected - search results still include content from the specified domains.

## How I Debugged This

I patched `httpx.Client.send` to inspect the request body being sent to the Vertex AI API:

```python
import httpx
import json

original_send = httpx.Client.send

def patched_send(self, request, **kwargs):
if 'aiplatform' in str(request.url) and request.content:
data = json.loads(request.content)
print('REQUEST:', json.dumps(data.get('tools', []), indent=2))
return original_send(self, request, **kwargs)

httpx.Client.send = patched_send
```

This revealed that `exclude_domains` is not being converted to `excludeDomains` for the nested GoogleSearch object, even though the parent key `google_search` is correctly converted to `googleSearch`.

## Version Information

- google-genai: 1.59.0
- Python: 3.13

## Relevant Commits

- **7e4ec284** (2025-08-13): "feat: Support exclude_domains in Google Search and Enterprise Web Search" - This commit added `_GoogleSearch_to_vertex` which properly converted `exclude_domains` to `excludeDomains`
- **6c46d54b** (2025-10-03): "chore: Remove no-op converters" - This commit removed `_GoogleSearch_to_vertex`, and the functionality stopped working

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.