-
Notifications
You must be signed in to change notification settings - Fork 787
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:
Steps to reproduce
- Create a JSONL file for a Vertex AI Batch Prediction job.
- Format a row to include the
url_contexttool, eg:
{"request": {"contents":[{"role": "user", "parts": [{"text": "Summarize the content of this URL: https://example.com"}]}],"tools": [{"url_context": {}}]}}- Upload the JSONL file to Google Cloud Storage.
- Submit the Batch Prediction job using the
v1beta1endpoint.
Sample code to reproduce on Colab
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]