From 159a5e47f74ead513c905e3848ed6c6e49903887 Mon Sep 17 00:00:00 2001 From: factnn <166481866+factnn@users.noreply.github.com> Date: Sun, 21 Jun 2026 15:52:28 +0800 Subject: [PATCH] fix: also strip extra fields in image/file message paths for Mistral _extract_fields helper now also runs in _transform_messages_sync and _transform_messages_async for the image/file early-return path, preventing the same "Extra inputs are not permitted" error when messages mix image/file content with extra fields. --- litellm/llms/mistral/chat/transformation.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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]: