From 88f482a79ae6cd37aaceadd76a6f9913af0f91f0 Mon Sep 17 00:00:00 2001 From: JingHao-Leon <102573344+JingHao-Leon@users.noreply.github.com> Date: Tue, 20 Oct 2026 03:23:32 +0800 Subject: [PATCH] fix(mistral): keep existing provider_specific_fields on the delta and document the raw block list The reviewer on this PR pointed out two things about the new mistral_content_blocks field: - it carries the whole provider block list, so thinking/text blocks show up next to reasoning_content; the comment now states plainly that the field is the raw provider input, not a filtered citation list. - chunk_parser assigned delta["provider_specific_fields"] outright, which would drop a value the provider had already put on the delta. The existing dict is now updated in place; the field is only created when absent. Tests: 57 passed before and after (tests/unit/llms/mistral/test_mistral_chat_transformation.py). --- litellm/llms/mistral/chat/transformation.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/litellm/llms/mistral/chat/transformation.py b/litellm/llms/mistral/chat/transformation.py index a8e5ad90629..738955b1790 100644 --- a/litellm/llms/mistral/chat/transformation.py +++ b/litellm/llms/mistral/chat/transformation.py @@ -617,6 +617,10 @@ class MistralConfig(OpenAIGPTConfig): # The flattened content string cannot carry Mistral # citation chunks; keep the original block list # reachable instead of dropping them silently. + # This is the list exactly as the provider sent it + # -- thinking and text blocks included, not only the + # reference blocks -- so the field is the raw + # provider input, not a filtered citation list. choice["message"]["mistral_content_blocks"] = content if thinking_content: choice["message"]["reasoning_content"] = thinking_content @@ -730,7 +734,12 @@ class MistralChatResponseIterator(OpenAIChatCompletionStreamingHandler): ): # citation chunks carry no text; expose them on # provider_specific_fields instead of dropping them - delta["provider_specific_fields"] = {"mistral_content_blocks": content} + existing_fields = delta.get("provider_specific_fields") + if isinstance(existing_fields, dict): + # keep whatever the provider already put there + existing_fields["mistral_content_blocks"] = content + else: + delta["provider_specific_fields"] = {"mistral_content_blocks": content} except Exception: # Fall back to default parsing if custom handling fails return super().chunk_parser(chunk)