OpenRouter API leads to pydantic_ai.exceptions.UnexpectedModelBehavior: Exceeded maximum retries (1) for result validation. Deeper dive shown: "Plain text responses are not permitted, please call one of the functions instead" #822
Labels
more info
More information required
Title: OpenRouter API Not Providing Structured Response - Exceeded Maximum Retries for Result Validation
Description:
When using the OpenRouter API with
meta-llama/llama-3.3-70b-instruct
, I encounter an issue where the structured response is not returned, resulting in an exception after exceeding the maximum number of retries. However, the same code works as expected when using theopenai:gpt-4o-mini
model.Steps to Reproduce:
Setup Code:
Run the script with OpenRouter API:
Run the script with GPT 4o MINI (Successful Case):
Additional Context:
The issue seems to be related to the way the OpenRouter API handles structured responses. The error message indicates that the model behavior is unexpected, and the code exceeds the maximum retries for result validation:
I suspect that the OpenRouter API does not allow plain text responses and expects a structured function call response. Meanwhile, the GPT 4o MINI model handles the structured response correctly.
Core Function Example (Related to Entity Description):
Expected Behavior:
Actual Behavior:
The OpenRouter API returns a plain text response, leading to a validation failure after one retry, and the following error is raised:
In contrast, using the GPT 4o MINI model produces the expected output.
Environment:
https://openrouter.ai/api/v1
), OpenAI API (for GPT 4o MINI)Additional Notes:
LogfireNotConfiguredWarning
is noted but does not appear to be directly related to the structured response issue.Request:
Could you please investigate why the OpenRouter API is not returning the structured response and causing a result validation failure? Any insights into how to configure the API or modify the code to handle this behavior would be appreciated.
The text was updated successfully, but these errors were encountered: