-
Notifications
You must be signed in to change notification settings - Fork 808
pydantic_ai.exceptions.UnexpectedModelBehavior: Exceeded maximum retries (1) for result validation #200
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
Experiencing similar results in every tool-enabled ollama model that I've tried so far. |
A bit more experimentation later. Here is a logfire span detailing a failing run. It appears to use my own defined tools correctly, but falls flat when trying to structure it as defined. class QueryResponse(BaseModel):
category: str
index: str
reply: str |
This "worked" for me, although the response is incorrect: from pydantic import BaseModel, Field
from pydantic_ai import Agent
class SupportResult(BaseModel):
support_advice: str = Field(description='Advice returned to the customer')
block_card: bool = Field(description='Whether to block their')
risk: int = Field(description='Risk level of query', ge=0, le=10)
support_agent = Agent(
'ollama:llama3.2',
result_type=SupportResult,
system_prompt=(
'You are a support agent in our bank, give the '
'customer support and judge the risk level of their query. '
),
)
r = support_agent.run_sync('A customer has lost their card, what should I do?')
print(r.data)
#> support_advice='Please contact our bank’s lost and found department immediately at phone number XXX-XXXX to report your card missing. We will guide you through the next steps and provide a new card as soon as possible.' block_card=False risk=1 If you're seeing issues with a model failing to generate a valid response, I'm afraid that's a limitation of the model, there's not much we can do. You might want to add: try:
result = support_agent.run_sync('What is my balance?', deps=deps)
except UnexpectedModelBehavior:
print(support_agent.last_run_messages)
raise So you can see the messages exchanged and understand what went wrong, or use logfire. |
See #242 - looks like Ollama now has dedicated support for structured responses which might help with this. |
I got the same error but fixed it by simply instructing Ollama to output its result in JSON format. |
When I use Llama3.2. that time I got the error.
Code:
The text was updated successfully, but these errors were encountered: