fix: handle Mistral Magistral structured content blocks - #4748
Closed
teknium1 wants to merge 1 commit into
Closed
Conversation
Mistral Magistral reasoning models (and mistral-large-2512+) return
message content as a list of typed blocks instead of a plain string:
[{"type": "thinking", "thinking": [{"type": "text", "text": "..."}]},
{"type": "text", "text": "final answer"}]
This happens in both streaming deltas and non-streaming responses,
causing TypeError: sequence item 0: expected str instance, list found
when the code tries to join content parts.
Changes:
- Add _normalize_structured_content() helper that extracts text and
thinking parts from Mistral structured blocks
- Fix streaming path: normalize delta.content before appending to
content_parts, route thinking to reasoning_parts
- Fix non-streaming normalization: use the helper to also extract
thinking blocks as reasoning_content (was silently dropping them)
- Fix _build_assistant_message: normalize list content before
string operations
- Fix length truncation/continuation paths: normalize content
before string concatenation
- Add 25 tests covering the helper, streaming, non-streaming,
and _build_assistant_message paths
Fixes the reported CLI/Discord bot crash when using magistral-latest
or magistral-medium-latest via api.mistral.ai.
Contributor
Author
|
Closing during PR triage — not pursuing this approach. |
5 tasks
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mistral Magistral reasoning models (magistral-medium-latest, magistral-small-latest) and mistral-large-2512+ return message.content as a list of structured blocks instead of a plain string:
This happens in both streaming deltas and non-streaming responses, causing
TypeError: sequence item 0: expected str instance, list foundwhen the code tries to join content_parts.Reported by Joseph C. on Discord.
Changes
_normalize_structured_content()helper that extracts text and thinking parts from Mistral structured blocksTest plan