Skip to content

Commit 8611b4f

Browse files
conradleeclaude
andcommitted
Add test confirming gemini-2.5-flash recursive schema support on GLA
This test verifies that Google has fixed the issue where gemini-2.5-flash would return 500 errors when using recursive schemas with $refs on the GLA (Generative Language API) endpoint. The test successfully passes, confirming that: - Recursive schemas with $defs and $refs now work on GLA - gemini-2.5-flash properly handles TreeNode structures - Google's enhanced JSON Schema support is fully functional This validates that we can use the same JSON schema transformer for both GLA and Vertex AI endpoints without needing defensive workarounds. Test cassette has been reviewed and contains no sensitive information. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8dcf07a commit 8611b4f

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
interactions:
2+
- request:
3+
headers:
4+
accept:
5+
- '*/*'
6+
accept-encoding:
7+
- gzip, deflate
8+
connection:
9+
- keep-alive
10+
content-length:
11+
- '556'
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 tree with root "A" and two children "B" and "C"
21+
role: user
22+
generationConfig:
23+
responseJsonSchema:
24+
$defs:
25+
TreeNode:
26+
description: A node in a tree structure.
27+
properties:
28+
children:
29+
default: []
30+
items:
31+
$ref: '#/$defs/TreeNode'
32+
type: array
33+
value:
34+
type: string
35+
required:
36+
- value
37+
title: TreeNode
38+
type: object
39+
$ref: '#/$defs/TreeNode'
40+
title: TreeNode
41+
responseMimeType: application/json
42+
responseModalities:
43+
- TEXT
44+
uri: https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent
45+
response:
46+
headers:
47+
alt-svc:
48+
- h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
49+
content-length:
50+
- '612'
51+
content-type:
52+
- application/json; charset=UTF-8
53+
server-timing:
54+
- gfet4t7; dur=1444
55+
transfer-encoding:
56+
- chunked
57+
vary:
58+
- Origin
59+
- X-Origin
60+
- Referer
61+
parsed_body:
62+
candidates:
63+
- content:
64+
parts:
65+
- text: '{"value":"A","children":[{"value":"B"},{"value":"C"}]}'
66+
role: model
67+
finishReason: STOP
68+
index: 0
69+
modelVersion: gemini-2.5-flash
70+
responseId: D08Yaa3eKYmznsEPt4u8gAk
71+
usageMetadata:
72+
candidatesTokenCount: 16
73+
promptTokenCount: 20
74+
promptTokensDetails:
75+
- modality: TEXT
76+
tokenCount: 20
77+
thoughtsTokenCount: 183
78+
totalTokenCount: 219
79+
status:
80+
code: 200
81+
message: OK
82+
version: 1

tests/models/test_google.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,6 +3226,29 @@ class TreeNode(BaseModel):
32263226
assert {child.value for child in result.output.children} == {'B', 'C'}
32273227

32283228

3229+
async def test_google_recursive_schema_native_output_gemini_2_5_gla(
3230+
allow_model_requests: None, google_provider: GoogleProvider
3231+
):
3232+
"""Test recursive schemas with gemini-2.5-flash on GLA.
3233+
3234+
This previously failed with 500 errors but should now work after Google's fix.
3235+
"""
3236+
m = GoogleModel('gemini-2.5-flash', provider=google_provider)
3237+
3238+
class TreeNode(BaseModel):
3239+
"""A node in a tree structure."""
3240+
3241+
value: str
3242+
children: list[TreeNode] = []
3243+
3244+
agent = Agent(m, output_type=NativeOutput(TreeNode))
3245+
3246+
result = await agent.run('Create a simple tree with root "A" and two children "B" and "C"')
3247+
assert result.output.value == snapshot('A')
3248+
assert len(result.output.children) == snapshot(2)
3249+
assert {child.value for child in result.output.children} == snapshot({'B', 'C'})
3250+
3251+
32293252
async def test_google_dict_with_additional_properties_native_output(
32303253
allow_model_requests: None, google_provider: GoogleProvider
32313254
):

0 commit comments

Comments
 (0)