Skip to content

[Feat]: support setting 'type' in tools for google search tool #14644

@tanvithakur94

Description

@tanvithakur94

What happened?

We are trying to test out google search grounding example using gemini-2.5-pro model.

{
    "messages": [
        {
            "role": "system",
            "content": "You are expert at cricket."
        },
        {
            "role": "user",
            "content": "Give me asia cup 2025 scores point table."
        }
    ],
    "tools": [
        {
            "type": "google_search",
            "googleSearch": {}
        }
    ]
}

As per litellm docs, the recommended way of testing is as shown below which is basically not passing tool type:

from litellm import completion 

## SETUP ENVIRONMENT
# !gcloud auth application-default login - run this to add vertex credentials to your env

tools = [{"googleSearch": {}}] # 👈 ADD GOOGLE SEARCH

resp = litellm.completion(
                    model="vertex_ai/gemini-1.0-pro-001",
                    messages=[{"role": "user", "content": "Who won the world cup?"}],
                    tools=tools,
                )

print(resp)

since we follow OPENAI spec, tool type is a required field and when we pass it in as shown above, we are seeing error:
BadRequestError: VertexAIException BadRequestError - {\n \"error\": {\n \"code\": 400,\n \"message\": \"The GenerateContentRequest proto is invalid:\\n * tools[0].tool_type: required one_of 'tool_type' must have one initialized field\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n"

Can somebody please take a look?

The transformed request going to vendor is basically not having googlesearch in the tools spec, hence its erroring out:

{'contents': [{'role': 'user', 'parts': [{'text': 'Give me asia cup 2025 scores point table.'}]}], 'system_instruction': {'parts': [{'text': 'You are expert at cricket.'}]}, 'tools': [{'function_declarations': []}], 'safetySettings': [{'category': 'HARM_CATEGORY_HARASSMENT', 'threshold': 'BLOCK_NONE'}, {'category': 'HARM_CATEGORY_HATE_SPEECH', 'threshold': 'BLOCK_NONE'}, {'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'threshold': 'BLOCK_NONE'}, {'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold': 'BLOCK_NONE'}], 'generationConfig': {}}

The correct transformation would look something like this:

{'contents': [{'role': 'user', 'parts': [{'text': 'Give me asia cup 2025 scores point table.'}]}], 'system_instruction': {'parts': [{'text': 'You are expert at cricket.'}]}, 'tools': [{'function_declarations': [], 'googleSearch': {}}], 'safetySettings': [{'category': 'HARM_CATEGORY_HARASSMENT', 'threshold': 'BLOCK_NONE'}, {'category': 'HARM_CATEGORY_HATE_SPEECH', 'threshold': 'BLOCK_NONE'}, {'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'threshold': 'BLOCK_NONE'}, {'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'threshold': 'BLOCK_NONE'}], 'generationConfig': {}}

Relevant log output

Shared above

Are you a ML Ops Team?

Yes

What LiteLLM version are you on ?

v1.74.15.post2

Twitter / LinkedIn details

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions