Skip to content

Commit 9c70fb5

Browse files
conradleeclaude
andauthored
Fix Gemini nested tool argument schemas by removing title from $defs (#3487)
Co-authored-by: Claude <[email protected]>
1 parent 24e47bf commit 9c70fb5

File tree

5 files changed

+364
-30
lines changed

5 files changed

+364
-30
lines changed

pydantic_ai_slim/pydantic_ai/profiles/google.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def transform(self, schema: JsonSchema) -> JsonSchema:
4747
schema.pop('discriminator', None)
4848
schema.pop('examples', None)
4949

50+
# Remove 'title' due to https://github.com/googleapis/python-genai/issues/1732
51+
schema.pop('title', None)
52+
5053
type_ = schema.get('type')
5154
if type_ == 'string' and (fmt := schema.pop('format', None)):
5255
description = schema.get('description')
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
interactions:
2+
- request:
3+
headers:
4+
accept:
5+
- '*/*'
6+
accept-encoding:
7+
- gzip, deflate
8+
connection:
9+
- keep-alive
10+
content-length:
11+
- '1298'
12+
content-type:
13+
- application/json
14+
host:
15+
- generativelanguage.googleapis.com
16+
method: POST
17+
parsed_body:
18+
contents:
19+
- parts:
20+
- text: Create a simple example with 2 pages, each with 2 items
21+
role: user
22+
generationConfig:
23+
responseJsonSchema:
24+
$defs:
25+
MiddleModel:
26+
description: Represents the middle nested level.
27+
properties:
28+
items:
29+
description: List of nested items
30+
items:
31+
$ref: '#/$defs/NestedModel'
32+
type: array
33+
title:
34+
description: Title of the page
35+
type: string
36+
required:
37+
- title
38+
- items
39+
title: MiddleModel
40+
type: object
41+
NestedModel:
42+
description: Represents the deepest nested level.
43+
properties:
44+
name:
45+
description: Name of the item
46+
type: string
47+
value:
48+
description: Value of the item
49+
type: integer
50+
required:
51+
- name
52+
- value
53+
title: NestedModel
54+
type: object
55+
description: Represents the top-level structure.
56+
properties:
57+
name:
58+
description: Name of the collection
59+
type: string
60+
pages:
61+
description: List of pages
62+
items:
63+
$ref: '#/$defs/MiddleModel'
64+
type: array
65+
required:
66+
- name
67+
- pages
68+
title: TopModel
69+
type: object
70+
responseMimeType: application/json
71+
responseModalities:
72+
- TEXT
73+
systemInstruction:
74+
parts:
75+
- text: You are a helpful assistant that creates structured data.
76+
role: user
77+
uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent
78+
response:
79+
headers:
80+
alt-svc:
81+
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
82+
content-length:
83+
- '797'
84+
content-type:
85+
- application/json; charset=UTF-8
86+
server-timing:
87+
- gfet4t7; dur=2103
88+
transfer-encoding:
89+
- chunked
90+
vary:
91+
- Origin
92+
- X-Origin
93+
- Referer
94+
parsed_body:
95+
candidates:
96+
- content:
97+
parts:
98+
- text: '{"name":"My Collection","pages":[{"title":"Page One","items":[{"name":"Item A","value":10},{"name":"Item
99+
B","value":20}]},{"title":"Page Two","items":[{"name":"Item C","value":30},{"name":"Item D","value":40}]}]}'
100+
role: model
101+
finishReason: STOP
102+
index: 0
103+
modelVersion: gemini-2.5-flash
104+
responseId: G9Eeaeh0u6CR1Q_10qWhBw
105+
usageMetadata:
106+
candidatesTokenCount: 64
107+
promptTokenCount: 26
108+
promptTokensDetails:
109+
- modality: TEXT
110+
tokenCount: 26
111+
thoughtsTokenCount: 360
112+
totalTokenCount: 450
113+
status:
114+
code: 200
115+
message: OK
116+
version: 1
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
interactions:
2+
- request:
3+
headers:
4+
accept:
5+
- '*/*'
6+
accept-encoding:
7+
- gzip, deflate
8+
connection:
9+
- keep-alive
10+
content-length:
11+
- '1379'
12+
content-type:
13+
- application/json
14+
host:
15+
- generativelanguage.googleapis.com
16+
method: POST
17+
parsed_body:
18+
contents:
19+
- parts:
20+
- text: Create a simple example with 2 pages, each with 2 items
21+
role: user
22+
generationConfig:
23+
responseModalities:
24+
- TEXT
25+
systemInstruction:
26+
parts:
27+
- text: You are a helpful assistant that creates structured data.
28+
role: user
29+
toolConfig:
30+
functionCallingConfig:
31+
allowedFunctionNames:
32+
- final_result
33+
mode: ANY
34+
tools:
35+
- functionDeclarations:
36+
- description: Represents the top-level structure.
37+
name: final_result
38+
parameters_json_schema:
39+
$defs:
40+
MiddleModel:
41+
description: Represents the middle nested level.
42+
properties:
43+
items:
44+
description: List of nested items
45+
items:
46+
$ref: '#/$defs/NestedModel'
47+
type: array
48+
title:
49+
description: Title of the page
50+
type: string
51+
required:
52+
- title
53+
- items
54+
type: object
55+
NestedModel:
56+
description: Represents the deepest nested level.
57+
properties:
58+
name:
59+
description: Name of the item
60+
type: string
61+
value:
62+
description: Value of the item
63+
type: integer
64+
required:
65+
- name
66+
- value
67+
type: object
68+
properties:
69+
name:
70+
description: Name of the collection
71+
type: string
72+
pages:
73+
description: List of pages
74+
items:
75+
$ref: '#/$defs/MiddleModel'
76+
type: array
77+
required:
78+
- name
79+
- pages
80+
title: TopModel
81+
type: object
82+
uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent
83+
response:
84+
headers:
85+
alt-svc:
86+
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
87+
content-length:
88+
- '2943'
89+
content-type:
90+
- application/json; charset=UTF-8
91+
server-timing:
92+
- gfet4t7; dur=2257
93+
transfer-encoding:
94+
- chunked
95+
vary:
96+
- Origin
97+
- X-Origin
98+
- Referer
99+
parsed_body:
100+
candidates:
101+
- content:
102+
parts:
103+
- functionCall:
104+
args:
105+
name: Example Collection
106+
pages:
107+
- items:
108+
- name: Item A
109+
value: 1
110+
- name: Item B
111+
value: 2
112+
title: Page 1
113+
- items:
114+
- name: Item C
115+
value: 3
116+
- name: Item D
117+
value: 4
118+
title: Page 2
119+
name: final_result
120+
thoughtSignature: Cu0HAdHtim/Us0P5TwBWE7yYzcsEdZQ1lCnTajHuXXzYUQcnrY+KXPclwqZ8upv3qmjNgTs8ahVMRiGHhHxGJ0qSjCtlo2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cM9CCzV4NVH+2nvlEXYrEts6SV5iaztophBU74/dNWzAy9DlnihfIrYxRNTCgOJMXwSquViyKeeQk9eH61QvK2MF052bA68VkBGfgne0FHtG4n0bvpLO73KTH8aGcrvb0zIIpu13pT7GFACQDl5cR/R/y9sWDuoyh6LBG
121+
role: model
122+
finishMessage: Model generated function call(s).
123+
finishReason: STOP
124+
index: 0
125+
modelVersion: gemini-2.5-flash
126+
responseId: X94eaezvBLO1vdIP6brwoQc
127+
usageMetadata:
128+
candidatesTokenCount: 93
129+
promptTokenCount: 219
130+
promptTokensDetails:
131+
- modality: TEXT
132+
tokenCount: 219
133+
thoughtsTokenCount: 323
134+
totalTokenCount: 635
135+
status:
136+
code: 200
137+
message: OK
138+
version: 1

0 commit comments

Comments
 (0)