googleapis / googleapis/python-genai

Function calling incorrectly interprets title fields in nested JSON schemas as callable functions

Aperta
#1,732 6 commenti 4 reazioni 1 assegnatario Assegnata a @kkorpal Vedi su GitHub
priority: p2 type: bug
Lingua principale
Python
Stelle
4k
Fork
1k
Merge medio
2g 12h
PR unite (30g)
41

Descrizione

When using the Google genai Python SDK for function calling with nested JSON schemas, Gemini incorrectly treats title fields in $defs definitions as callable Python functions, resulting in MALFORMED_FUNCTION_CALL errors.

#### Environment details

- Programming language: python
- OS: macos
- Language runtime version: 3.12
- Package version: 2.8.1

#### Steps to reproduce

```python
import asyncio
from google.genai import Client
from pydantic import BaseModel, Field
from pydantic.type_adapter import TypeAdapter

class NestedModel(BaseModel):
name: str = Field(description='Name of the item')
value: int = Field(description='Value of the item')

class MiddleModel(BaseModel):
title: str = Field(description='Title of the page')
items: list[NestedModel] = Field(description='List of nested items')

class TopModel(BaseModel):
name: str = Field(description='Name of the collection')
pages: list[MiddleModel] = Field(description='List of pages')

# Generate schema with $ref/$defs (standard Pydantic behavior)
schema = TypeAdapter(TopModel).json_schema()

config_dict = {
'tools': [
{
'function_declarations': [
{
'name': 'final_result',
'description': 'Return the final result',
'parameters_json_schema': schema,
}
]
}
],
'tool_config': {'function_calling_config': {'mode': 'ANY', 'allowed_function_names': ['final_result']}},
}

async def test():
client = Client(api_key='YOUR_API_KEY')

response = await client.aio.models.generate_content(
model='gemini-2.5-flash',
contents='Create a simple example with 2 pages',
config=config_dict,
)
print(response)

asyncio.run(test())

```

Expected output: Valid function call with JSON matching the schema
Actual output : MALFORMED_FUNCTION_CALL or attempts to call MiddleModel/NestedModel as functions
Making sure to follow these steps will guarantee the quickest resolution possible.

**Impact**

This prevents users from:
- Using standard Pydantic schema generation with nested models
- Leveraging $ref/$defs for schema reuse and organization
- Building complex, deeply nested structured output schemas

Users must either:
- Manually strip title fields from nested schemas (workaround)
- Use responseJsonSchema with native structured output instead (different API)
- Inline all nested schemas, losing the benefits of $ref/$defs`

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.