Skip to content

Function calling mode ANY + function declaration without parameters = INVALID_ARGUMENT #981

Open
@DouweM

Description

@DouweM

Using FunctionCallingConfigMode.ANY with a FunctionDeclarationDict without parameters results in this error:

google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Request contains an invalid argument.', 'status': 'INVALID_ARGUMENT'}}

Code to reproduce:

import os

from google import genai
from google.genai.types import (
    FunctionCallingConfigDict,
    FunctionCallingConfigMode,
    FunctionDeclarationDict,
    GenerateContentConfigDict,
    ToolConfigDict,
    ToolDict,
)

client = genai.Client(api_key=os.getenv('GEMINI_API_KEY'))

result = client.models.generate_content(
    model='gemini-2.0-flash',
    contents='Test 123',
    config=GenerateContentConfigDict(
        tools=[
            ToolDict(function_declarations=[FunctionDeclarationDict(name='something')]),
        ],
        tool_config=ToolConfigDict(
            function_calling_config=FunctionCallingConfigDict(
                mode=FunctionCallingConfigMode.ANY,
            ),
        ),
    ),
)

I'm a maintainer of Pydantic AI, this was reported to us by a few users at pydantic/pydantic-ai#1990. One of them says it used to work last week but does no longer, so this look like an API-side regression. Please let me know if there's a more appropriate place to file API issues.

Metadata

Metadata

Assignees

Labels

api: gemini-apipriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions