Skip to content

Commit 02a8231

Browse files
conradleeclaude
andcommitted
Address maintainer review: fix comment typo and add prefixItems test
1. **Fix comment typo in google.py (line 270)**: - Changed `response_schema` to `response_json_schema` to match actual field usage - Addresses DouweM's suggestion for accuracy 2. **Add test for prefixItems native support**: - New test `test_google_prefix_items_native_output` verifies tuple types work natively - Uses `tuple[float, float]` which generates `prefixItems` in JSON schema - Confirms we no longer need the prefixItems → items conversion workaround - Tests with NYC coordinates as a practical example Note: Cassette will be recorded by CI or during maintainer review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 36b2e38 commit 02a8231

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pydantic_ai_slim/pydantic_ai/models/google.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ async def count_tokens(
267267
messages, model_settings, model_request_parameters
268268
)
269269

270-
# Annoyingly, the type of `GenerateContentConfigDict.get` is "partially `Unknown`" because `response_schema` includes `typing._UnionGenericAlias`,
270+
# Annoyingly, the type of `GenerateContentConfigDict.get` is "partially `Unknown`" because `response_json_schema` includes `typing._UnionGenericAlias`,
271271
# so without this we'd need `pyright: ignore[reportUnknownMemberType]` on every line and wouldn't get type checking anyway.
272272
generation_config = cast(dict[str, Any], generation_config)
273273

tests/models/test_google.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,6 +3297,27 @@ class Task(BaseModel):
32973297
assert isinstance(result.output.priority.value, int)
32983298

32993299

3300+
async def test_google_prefix_items_native_output(allow_model_requests: None, google_provider: GoogleProvider):
3301+
"""Test prefixItems (tuple types) work natively without conversion to items."""
3302+
m = GoogleModel('gemini-2.5-flash', provider=google_provider)
3303+
3304+
class Coordinate(BaseModel):
3305+
"""A 2D coordinate with latitude and longitude."""
3306+
3307+
point: tuple[float, float] # This generates prefixItems in JSON schema
3308+
3309+
agent = Agent(m, output_type=NativeOutput(Coordinate))
3310+
3311+
result = await agent.run('Give me coordinates for New York City: latitude 40.7128, longitude -74.0060')
3312+
assert len(result.output.point) == snapshot(2)
3313+
# Verify both values are floats
3314+
assert isinstance(result.output.point[0], float)
3315+
assert isinstance(result.output.point[1], float)
3316+
# Rough check for NYC coordinates (latitude ~40, longitude ~-74)
3317+
assert 40 <= result.output.point[0] <= 41
3318+
assert -75 <= result.output.point[1] <= -73
3319+
3320+
33003321
def test_google_process_response_filters_empty_text_parts(google_provider: GoogleProvider):
33013322
model = GoogleModel('gemini-2.5-pro', provider=google_provider)
33023323
response = _generate_response_with_texts(response_id='resp-123', texts=['', 'first', '', 'second'])

0 commit comments

Comments
 (0)