Logo

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.

Original Error Message

Raw

Unexpected role received for serving. Expected 'User' or 'Tool' but got 'Assistant'.

Original Error Message

Raw

Unexpected role received for serving. Expected 'User' or 'Tool' but got 'Assistant'.

© 2024 Portkey, Inc. All rights reserved

HIPAA

COMPLIANT

GDPR

Transform Your AI app prototypes to be production-ready

Talk to us →