fix(mistral): strip reasoning_content from assistant input messages

When an assistant message includes `reasoning_content` (added by litellm when parsing a Mistral thinking response), and that message is replayed in subsequent requests, Mistral rejects the whole request with 422 `extra_forbidden` because `reasoning_content` is not a valid input field.

Fix: in `_transform_messages`, pop `reasoning_content` from assistant messages before forwarding to the Mistral API. This is consistent with the existing `strip_none_values_from_message` call that already prevents similar `extra_forbidden` errors.

Fixes #30835.
This commit is contained in:
Vitaliy 2026-06-21 00:08:37 -04:00 • committed by GitHub
parent dcf1b445e6
commit 5c4fe9ca58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -268,6 +268,9 @@ class MistralConfig(OpenAIGPTConfig):
m = MistralConfig._handle_tool_call_message(m)
if MistralConfig._is_empty_assistant_message(m):
continue
# Strip reasoning_content from assistant messages — Mistral rejects it as input (extra_forbidden)
if m.get("role") == "assistant":
m.pop("reasoning_content", None)
m = strip_none_values_from_message(m) # prevents 'extra_forbidden' error
new_messages.append(m)