googleapis / googleapis/python-genai

BUG: Vertex AI Batch Prediction rejects valid `url_context` payload (Schema validation mismatch with Online Prediction)

Open
#2,123 4 comments 0 reactions 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p2 type: bug
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

#### Overview

There is a schema validation mismatch between the standard Vertex AI Online Prediction API and the Vertex AI Batch Prediction API regarding tools with no fields, such as `url_context`.

When utilizing the `url_context` tool (currently in `v1beta1`), the Gemini API requires it to be passed as an empty object within the tools array: `{"url_context": {}}`. While standard Online Prediction accepts this empty object and works correctly, the Vertex AI Batch Prediction service rejects the exact same payload due to strict server-side JSONL schema validation expecting nested fields.
NB: For the `google_search` tool, adding `"timeRangeFilter": null` can be used as a workaround (see Community Post 2 linked below) but not for others like `url_context`.

#### Environment details

- Package Name: google-genai (Python)
- Package Version: 1.65.0
- Service: Vertex AI Batch Prediction
- API Version: v1beta1
- Environment: Google Colab
- Related Community Posts:
- https://discuss.ai.google.dev/t/vertex-ai-batch-mode-url-context/94615
- https://discuss.ai.google.dev/t/how-to-properly-use-the-google-search-tool-in-batch-requests-validationerror-internal-error/93079/14

#### Steps to reproduce

1. Create a JSONL file for a Vertex AI Batch Prediction job.
2. Format a row to include the `url_context` tool, eg:
```json
{"request": {"contents":[{"role": "user", "parts": [{"text": "Summarize the content of this URL: https://example.com"}]}],"tools": [{"url_context": {}}]}}
```
3. Upload the JSONL file to Google Cloud Storage.
4. Submit the Batch Prediction job using the `v1beta1` endpoint.

#### Sample code to reproduce on Colab

```python
from google.colab import auth
auth.authenticate_user()

from google import genai
from google.genai.types import CreateBatchJobConfig

# replace with relevant values
PROJECT_ID = ""
BUCKET_NAME = ""
INPUT_PATH = ""
OUTPUT_PATH = ""
JSONL_PAYLOADS_NAME = ""

LOCATION = "global"
MODEL_ID = "gemini-3-flash-preview"

INPUT_DATA = f"gs://{BUCKET_NAME}/{INPUT_PATH}/{JSONL_PAYLOADS_NAME}"
BUCKET_URI = f"gs://{BUCKET_NAME}/{OUTPUT_PATH}/"

client = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION)

gcs_batch_job = client.batches.create(
model=MODEL_ID,
src=INPUT_DATA,
config=CreateBatchJobConfig(dest=BUCKET_URI),
)
```

### Expected Behavior

The Batch Prediction parser should accept the empty `url_context` object and process the batch job, mirroring the behavior of the online `generateContent` API.

### Actual Behavior
The batch job fails immediately during the initial parsing phase with the following error:
`Query error: Cannot store struct 'request.tools.url_context' with no fields at [1:1]`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.