Conversation
_emit_argument_normalization marked non-string arguments |tojson|safe, which stays a markupsafe.Markup. Markup.__radd__ takes priority over str.__add__, so concatenating it into the hand-written JSON scaffolding with '+' HTML-escaped the surrounding literal quotes instead of leaving them alone. Use `~ ''` instead, which forces Jinja's str_join path (plain str() on every piece) rather than the Markup-preserving `string` filter. Fixes mistralai#311.
Author
|
Flagging this one, green for about a week with no review yet. The fix is one call in template_generator.py (swap the Markup concatenation for a plain str), the rest of the diff is the jinja fixture regeneration. |
This branch has not been deployed
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.
Fixes #311.
tojsonreturns amarkupsafe.Markup(astrsubclass), andMarkup.__radd__takes priority overstr.__add__on a plain-string left operand._emit_argument_normalizationmarked the normalizedarguments|safe, so every place that later did'{"name": "' + name + ...' + arguments + '}'got the literal quotes aroundname/arguments/idHTML-escaped to", corrupting the JSON. Theargumentsvalue itself was never touched, which is why it was easy to miss in a spot check: only the surrounding hand-written punctuation broke.Jinja's
stringfilter doesn't fix this (it'ssoft_str, which deliberately preservesMarkupsoescape()still runs on it later).~ ''does, since~compiles tostr_join, which plain-str()s every piece before joining, same as the reproduction in the issue confirmed by hand.Added
test_tool_call_dict_arguments_produce_valid_json(v2/v3/v3-spm/v7) asserting no"in the output and that both"name"and"arguments"render as literal JSON. Reverting just the~ ''line turns it red again, same container both times. Regenerated the 26 golden.jinjafixtures that embed_emit_argument_normalization's output; each diff is the single changed line.pytest tests/,--doctest-modules ./src,ruff,mypyandpre-commitare all clean, and the fulltests/integrations/suite (parity + transformers) passes.