Skip to content

Commit 0260a31

Browse files
authored
Allow default in tool schema with Gemini (#2309)
1 parent 004d63b commit 0260a31

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

pydantic_ai_slim/pydantic_ai/profiles/google.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def transform(self, schema: JsonSchema) -> JsonSchema:
4949
)
5050

5151
schema.pop('title', None)
52-
schema.pop('default', None)
5352
schema.pop('$schema', None)
5453
if (const := schema.pop('const', None)) is not None:
5554
# Gemini doesn't support const, but it does support enum with a single value

tests/models/test_gemini.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async def test_require_response_tool(allow_model_requests: None):
194194

195195
async def test_json_def_replaced(allow_model_requests: None):
196196
class Axis(BaseModel):
197-
label: str
197+
label: str = Field(default='<unlabeled axis>', description='The label of the axis')
198198

199199
class Chart(BaseModel):
200200
x_axis: Axis
@@ -213,8 +213,14 @@ class Locations(BaseModel):
213213
{
214214
'$defs': {
215215
'Axis': {
216-
'properties': {'label': {'title': 'Label', 'type': 'string'}},
217-
'required': ['label'],
216+
'properties': {
217+
'label': {
218+
'default': '<unlabeled axis>',
219+
'description': 'The label of the axis',
220+
'title': 'Label',
221+
'type': 'string',
222+
}
223+
},
218224
'title': 'Axis',
219225
'type': 'object',
220226
},
@@ -268,17 +274,27 @@ class Locations(BaseModel):
268274
'items': {
269275
'properties': {
270276
'lat': {'type': 'number'},
271-
'lng': {'type': 'number'},
277+
'lng': {'default': 1.1, 'type': 'number'},
272278
'chart': {
273279
'properties': {
274280
'x_axis': {
275-
'properties': {'label': {'type': 'string'}},
276-
'required': ['label'],
281+
'properties': {
282+
'label': {
283+
'default': '<unlabeled axis>',
284+
'description': 'The label of the axis',
285+
'type': 'string',
286+
}
287+
},
277288
'type': 'object',
278289
},
279290
'y_axis': {
280-
'properties': {'label': {'type': 'string'}},
281-
'required': ['label'],
291+
'properties': {
292+
'label': {
293+
'default': '<unlabeled axis>',
294+
'description': 'The label of the axis',
295+
'type': 'string',
296+
}
297+
},
282298
'type': 'object',
283299
},
284300
},

0 commit comments

Comments
 (0)