-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AII confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issueTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Description
When manually passing a token limit to the agent that's too restrictive and causes the model run to fail, the error we raise is of the wrong type
from pydantic_ai import Agent
Agent("google-gla:gemini-2.5-pro-preview-05-06", model_settings=dict(max_tokens=5)).run_sync("write a haiku")
yields
UnexpectedModelBehavior: Content field missing from Gemini response, body: (...)
instead of UsageLimitExceeded
Example Code
from pydantic_ai import Agent
Agent("google-gla:gemini-2.5-pro-preview-05-06", model_settings=dict(max_tokens=5)).run_sync("write a haiku")
Python, Pydantic AI & LLM client version
Python 3.12.4
Pydantic 0.3.1
google-gla:gemini-2.5-pro-preview-05-06
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Close pydantic#2021: correctly raise UsageLimitExceeded instead of Un…
metaember commentedon Jun 18, 2025
I guess there's a deeper question of why this is not an issue with e.g.
'gemini-1.5-flash'
whereas it is with"google-gla:gemini-2.5-pro-preview-05-06"
, at least this pr fixes the error though