
mistral-ai
#10145
role_assignment_error
Expected the last role to be user but received a different role. Ensure proper role assignment in your configuration.
This error has been identified and solved.
Reason
The error you are encountering with the Mistral AI API, specifically the message "Expected last role User or Tool (or Assistant with prefix True) for serving but got RoleEnum.system," indicates a problem with the role configuration in your API request.
Here is a concise explanation of the issue:
The Mistral API expects the last role in the conversation to be either "User" or "Tool" (or "Assistant" with a specific prefix), but your request is ending with a role that is not compliant with these expectations, specifically "RoleEnum.system".
This mismatch in role configuration causes the API to interpret the request as invalid, leading to a "Bad Request" error with a status code of 400.
Solution
To fix the 400 status error in the Mistral AI API due to the incorrect last role, you need to adjust the role configuration in your API requests. Here are the key steps:
Ensure the last message in the conversation has a role of "User" or "Tool".
If using the "Assistant" role, make sure it has the prefix feature enabled.
Key Adjustments:
Change the last role to "User" or "Tool".
Enable the prefix feature for the "Assistant" role if necessary.
Verify that the conversation flow adheres to Mistral's role expectations.
Suggested Links
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://community.crewai.com/t/crewai-on-mistral-api-error/1559
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://github.com/mistralai/client-python/blob/main/README.md
https://github.com/langchain-ai/langchain/issues/23703
https://github.com/microsoft/autogen/issues/991
https://community.meraki.com/t5/Developers-APIs/API-Looping-createOrganizationAdmin-returns-400-Bad-Request/m-p/239525