Logo

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.

Original Error Message

Raw

Expected the last role to be user but received a different role. Ensure proper role assignment in your configuration.

Original Error Message

Raw

Expected the last role to be user but received a different role. Ensure proper role assignment in your configuration.

© 2024 Portkey, Inc. All rights reserved

HIPAA

COMPLIANT

GDPR

Transform Your AI app prototypes to be production-ready

Talk to us →