
mistral-ai
#10573
response_role_error
Unexpected role received for serving. Expected 'User' or 'Tool' but got 'Assistant'.
This error has been identified and solved.
Reason
The error you're encountering with the Mistral AI API, specifically the message "Expected last role User or Tool (or Assistant with prefix True) for serving but got assistant," indicates that the API is receiving an invalid role configuration in the request payload.
Here’s a concise explanation:
The Mistral API expects the last message in the chat to be either a "User" or "Tool" role, or an "Assistant" role but only if the prefix feature is enabled.
In your case, the last message is an "Assistant" role without the prefix feature enabled, which is not accepted by the Mistral API, leading to a "Bad Request" (400 error) response.
Solution
To fix the "Expected last role User or Tool (or Assistant with prefix True) for serving but got assistant" error in the Mistral AI API, you need to adjust the role configuration in your request. Here are the steps to resolve this issue:
Ensure that the last message in the chat sequence is set to either a "User" or "Tool" role. If you need to use the "Assistant" role, you must enable the prefix feature.
Set the last message role to "User" or "Tool".
If using the "Assistant" role, enable the prefix feature.
Verify that the API request payload reflects these changes correctly.
Suggested Links
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://github.com/langchain-ai/langchain/issues/23703
https://community.openai.com/t/request-failed-with-status-code-400/39242
https://community.openai.com/t/error-400-already-has-an-active-run/930753
https://forum.cloudron.io/topic/11826/using-mistral-api-seems-broken-on-cloudron
https://community.crewai.com/t/crewai-on-mistral-api-error/1559
https://learn.microsoft.com/en-us/answers/questions/2117664/my-mistral-large-2407-serverless-deployment-api-is
https://jan.ai/docs/remote-models/mistralai