You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix nested Pydantic models in Gemini by removing title from $defs (fixes#3483)
## Problem
Gemini's function calling parser incorrectly interprets 'title' fields in
nested JSON Schema definitions ($defs) as callable Python functions, causing
MALFORMED_FUNCTION_CALL errors when using nested Pydantic models.
## Root Cause
When a schema like this is sent to Gemini:
```json
{
"$defs": {
"MiddleModel": {
"title": "MiddleModel", // ← Gemini treats this as a callable
"type": "object"
}
}
}
```
Gemini tries to generate Python constructor calls like:
`MiddleModel(title="...", items=[...])`
Instead of JSON:
`{"title": "...", "items": [...]}`
## Solution
Remove 'title' from nested schemas (those in $defs) while preserving:
- $ref/$defs structure (better schema organization)
- Top-level title (needed for function declaration name)
This is simpler than the original approach of inlining all $ref definitions.
## Testing
- Added test_google_nested_models_without_native_output (reproduces issue)
- Added test_google_nested_models_with_native_output (workaround verification)
- All 81 Google model tests pass
- Verified with real Gemini API calls
## Related Issues
- Fixes#3483
- Reported to Google SDK: googleapis/python-genai#1732
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
0 commit comments