How to properly use the Google Search tool in batch requests? (ValidationError & Internal Error)

Hello, Gemini Community

I am trying to use the google_search tool (or grounding) in batch mode, but am running into errors. Here’s my code which I copied from the documentation.

inline_requests_list = [
{‘contents’: [{‘parts’: [{‘text’: ‘Who won the euro 1998?’}]}]},
{‘contents’: [{‘parts’: [{‘text’: ‘Who won the euro 2025?’}]}], ‘tools’: [{‘google_search’: {}}]}
]

2. Create the batch job with the inline requests.

print(“Creating inline batch job…”)
inline_batch_job = client.batches.create(
model=“gemini-2.5-pro”,
src=inline_requests_list,
config={
‘display_name’: “inlined-requests-job-1”,
},
)

I recieve the following error :

--------------------------------------------------------------------------- Va in Batches.create(self, model, src, config) 5240 raise ValueError( 5241 ‘inlined_requests is not supported in Vertex AI. Please use’ 5242 ’ Google Cloud Storage URI or BigQuery URI instead.’ 5243 ) 5245 config = _extra_utils.format_destination(src, config) → 5246 return self._create(model=model, src=src, config=config) File …
in Batches._create(self, model, src, config) 4863 def _create( 4864 self, 4865 *, (…) 4868 config: Optional[types.CreateBatchJobConfigOrDict] = None, 4869 ) → types.BatchJob: → 4870 parameter_model = types._CreateBatchJobParameters( 4871 model=model, 4872 src=src, 4873 config=config, 4874 ) 4876 request_url_dict: Optional[dict[str, str]] 4878 if self._api_client.vertexai: File …
ValidationError: 3 validation errors for _CreateBatchJobParameters src.BatchJobSource Input should be a valid dictionary or object to extract fields from [type=model_attributes_type, input_value=[{‘contents’: [{‘parts’: …{‘google_search’: {}}]}], input_type=list] For further information visit “Modified by moderator” src.list[InlinedRequest].1.tools Extra inputs are not permitted [type=extra_forbidden, input_value=[{‘google_search’: {}}], input_type=list] For further information visit “Modified by moderator” src.str Input should be a valid string [type=string_type, input_value=[{‘contents’: [{‘parts’: …{‘google_search’: {}}]}], input_type=list] For further information visit

Also when I try to use the batch mode to receive a file as input, I receive an internal error (code: 13)

Does anyone know how to fix this or what I am doing wrong?

Hi @Sadegh_Rizi,

Welcome to the Google AI Forum! :confetti_ball: :confetti_ball:

In your code the batches.create() method expects a src pointing to an external data source and not a Python list of inline prompts.

Please check the documentation here

I recommend preparing a file in GCS and include Grounding as follows:

{
“contents”: [
{
“parts”: [{ “text”: “Who won the euro 1998?” }]
}
],
“tools”: [{ “google_search”: {} }]
}

Then update the file URI in src.. This should work.

Let me know if you are having any issues.

Happy coding :slight_smile: :slightly_smiling_face:

Hello @Krish_Varnakavi1,

Thanks for your response. I have already tried sending a batch request using a file as input. I created a jsonl file with the following content for instance :

{"key": "meaning_of_life", "request": {"contents": [{"parts": [{"text": "What is the meaning of life according to the famous philosophers"}]}], "tools": [{"google_search": {}}]}}

I uploaded the file and submitted the job with the following script

uploaded_file = client.files.upload(
    file='my-batch-requests.jsonl',
    config=types.UploadFileConfig(display_name='my-batch-requests', mime_type='jsonl')
)
file_batch_job = client.batches.create(
    model="gemini-2.5-pro",
    src=uploaded_file.name,
    config={
        
        'display_name': "test-1",
        
    },
)


then I will recieve the follwing error after retrieving the result :

{"error":{"message":"An internal error has occurred. Please retry or report in ...,"code":13},"key":"meaning_of_life"}

However, if I remove the “tools”: [{“google_search”: {}}] from my request, I will receive a correct response, which means there’s something wrong with the use of the google_search tool.

Thanks for your time and help.

Hi everyone, I’m having the same problem.
I tried both running with inline prompts and running with the prompts in the json file.
Without Google Search, it works perfectly, but when I add the tool, I get a validation error with the inline syntax. With the file, I get the same error reported by @Sadegh_Rizi

{
  "error": {
    "code": 13,
    "message": "An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting"
  },
  "key": "gp-f1"
}

Is this a bug?
Thanks.

Same issue here. If I add the tool to my JSONL batch file as per @Sadegh_Rizi’s code, I get the same internal error with code 13.

I also tried running it using the Vertex AI API, with the JSON uploaded to Google Storage.
The system also gives an error, before even reaching the inference.

Same issure here. It seems that inside genai, inlinedRequest only permits a list of contents. According to the offical document, it should accept a list of GenerateContentRequest.
I think it’s a bug. You can refer to the class definition of genai.types.InlinedRequest.

I tried everything also, vertex ai, grounding, google search. Then google API with batch, but apparently the new SDK is failing.
The only way I get it to work is using Gemini API but without batch so I hit the rate limit easily

Are we all using Python? Maybe it’s working in JavaScript, Java, or Go?

Hi everyone, I have found a new way to make it work in Vertex AI batch mode !
I’m using gemini-2.5-pro model, and the request should be constructed like this:

{
  "contents": [
    {
      "parts": [
        {
          "text": "What is the capital of France and who is its current president?"
        }
      ],
      "role": "user"
    }
  ],
  "tools": [
    {
      "googleSearch": {
        "timeRangeFilter": null
      }
    }
  ],
  "generationConfig": {
    "temperature": 0.1,
    "thinkingConfig": {
      "thinkingBudget": -1
    }
  }
}

In short, in Vertex AI batch mode, the keys should be in camel case, instead of Gemini dev AI’s snake case. The timeRangeFilter key in googleSearch tool is necessary, as Vertex AI does not allow a tool object with no field. The role has also to be set.
It seems that googleSearchRetrival tool is no longer supported in gemini-2.5 series.
This request works both for Google Cloud File format and BigQuery format.

3 Likes

I really wanted Conrad’s solution to work for me, but I also see these errors. Regularly getting “code 13”, exactly with his layout, with many different permutations of google_search/googleSearch, time_range_filter/timeRangeFilter, and including role. I think Batch mode with the google search tool appears to be just flat out broken.

This actually worked for me! Very good find! :flexed_biceps: