-
Notifications
You must be signed in to change notification settings - Fork 810
Large list[Model] result type causing pydantic_ai.exceptions.UnexpectedModelBehavior: Exceeded maximum retries
- bigger lists a problem?
#734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe this may be due in part to a bug where we are counting each individual validation error as a retry, rather than counting a collection of validation errors as a single retry. That probably explains why this is more commonly an issue when you are using large lists. Let me look into that, and then we can see if there is another issue going on. Related, I think we need to make it easier to debug validation errors like this, I'll try to think about how we can expose that more easily. |
Thanks, in my debugging of this issue, I had seen the parts or results return Curious, why and how the validation errors are happening/accumulating for large lists, if within my tool function I'm guaranteeing that the resultant return data is legal return data as per the return value pydantic model, is using the LLM in question to reparse and regenerate the content again? |
I noticed this happening for me on the antrhopic latest sonnet model and not on the google's gemini 2 flash. I have a simple result model:
but a long system prompt:
and the actual message:
|
I have an agent that is trying to return a list of objects as the return type for a tool. I'm using claude haiku 3.0 on AWS bedrock via the workaround here (#118 (comment)).
For single object returns and even nested and small lists, this works fine! However when trying to apply various agent and return patterns with our using tools and return types, I started running into the
pydantic_ai.exceptions.UnexpectedModelBehavior: Exceeded maximum retries
error message inconsistently.I initially saw this behavior similar to #200 as well as #523 - and other instances of this issue, however like I said, it works beautifully on small return values.
But at a certain size of an array the response gives me the
Exceeded maximum retries
error.In practice depending on the size of the strings in the objects, sometimes it fails at 5 instances, other times 15 or even 25.
Code
And to test it
In practice with our documents this has raised this exception at like lengths of 4. I don't fully understand how the token usage falls into this, I tried to up the size to see if it could be part of Claude's 4000 token response limit, but I'd seen it spill over no problem in some use cases, but fall over on other runs.
For the most part for returning matches to 1-3 items in this agentic workflow this is working fine, and it may be a bit odd to return so many rows to be interpreted by the LLM as part of the workflow. For one use case for us this could be a large RAG response from our vector store or full text query, or in the example above, it's a direct sql query for a series of documents affiliated to a program within our organization where we expecting more than 5 results to have it chained into another workflow.
The text was updated successfully, but these errors were encountered: