diff --git a/litellm/llms/mistral/chat/transformation.py b/litellm/llms/mistral/chat/transformation.py index 9de93ef94a6..ba44d9f2340 100644 --- a/litellm/llms/mistral/chat/transformation.py +++ b/litellm/llms/mistral/chat/transformation.py @@ -287,7 +287,7 @@ class MistralConfig(OpenAIGPTConfig): # and then apply Mistral-specific handling for files messages = await super()._transform_messages(messages, model, True) messages = self._handle_message_with_file(messages) - return messages + return self._strip_extra_fields(messages) def _transform_messages_sync(self, messages: List[AllMessageValues], model: str) -> List[AllMessageValues]: """Handle modification of messages for Mistral API in a sync context.""" @@ -296,6 +296,16 @@ class MistralConfig(OpenAIGPTConfig): # This is the sync version of the async method above messages = super()._transform_messages(messages, model, False) messages = self._handle_message_with_file(messages) + return self._strip_extra_fields(messages) + + @staticmethod + def _strip_extra_fields(messages: List[AllMessageValues]) -> List[AllMessageValues]: + for m in messages: + if isinstance(m, dict): + m.pop("metadata", None) + m.pop("provider_specific_fields", None) + m.pop("thinking_blocks", None) + m.pop("cache_control", None) return messages def _handle_message_with_file(self, messages: List[AllMessageValues]) -> List[AllMessageValues]: