diff --git a/pydantic_ai_slim/pydantic_ai/models/gemini.py b/pydantic_ai_slim/pydantic_ai/models/gemini.py index 3ca33cd35c..3fdd477b01 100644 --- a/pydantic_ai_slim/pydantic_ai/models/gemini.py +++ b/pydantic_ai_slim/pydantic_ai/models/gemini.py @@ -693,7 +693,7 @@ def simplify(self) -> dict[str, Any]: def _simplify(self, schema: dict[str, Any], refs_stack: tuple[str, ...]) -> None: schema.pop('title', None) - default = schema.pop('default', _utils.UNSET) + schema.pop('default', None) if ref := schema.pop('$ref', None): # noinspection PyTypeChecker key = re.sub(r'^#/\$defs/', '', ref) @@ -708,11 +708,12 @@ def _simplify(self, schema: dict[str, Any], refs_stack: tuple[str, ...]) -> None if any_of := schema.get('anyOf'): for item_schema in any_of: self._simplify(item_schema, refs_stack) - if len(any_of) == 2 and {'type': 'null'} in any_of and default is None: + if len(any_of) == 2 and {'type': 'null'} in any_of: for item_schema in any_of: if item_schema != {'type': 'null'}: schema.clear() schema.update(item_schema) + schema['nullable'] = True return type_ = schema.get('type') diff --git a/tests/models/test_gemini.py b/tests/models/test_gemini.py index 63de8cab90..75c835a777 100644 --- a/tests/models/test_gemini.py +++ b/tests/models/test_gemini.py @@ -267,6 +267,7 @@ class Locations(BaseModel): 'lng': {'type': 'number'}, }, 'required': ['lat', 'lng'], + 'nullable': True, 'type': 'object', } },