Repository navigation
fix(llm): keep non-ASCII text readable in repaired tool-call arguments - #8450
Open
notarbotdev wants to merge 1 commit into
Open
notarbotdev wants to merge 1 commit into
notarbotdev wants to merge 1 commit into
Conversation
_repaired_arguments_json wrote repaired arguments back with json.dumps'
default ensure_ascii=True, so accented text the model wrote ("recepción")
came back to it as \u escapes on the next turn. Models then imitate the
escapes in later calls and get them wrong ("recepci\u0013n": valid JSON
with a control character where the letter was).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
notarbotdev seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
What
_repaired_arguments_jsonwrites repaired tool-call arguments back to the chat history withjson.dumps(args_dict, default=str). The defaultensure_ascii=Trueturns every non-ASCII character into a\uXXXXescape, so text the model wrote as"recepción"comes back to it as"recepción"on the next turn.This PR adds
ensure_ascii=False, the same fix #7565 made for MCP results and task-group tool descriptions.Why it matters
Models imitate what they see in their own past calls. Once escapes are in the history, they start writing escapes themselves and get them wrong:
"recepci\u0013n","notar\u0000eda". That is valid JSON with a control character where the letter was, so nothing flags it and it reaches the tool.We saw this in production on 1.8.1, where every tool call was canonicalized (Spanish and Catalan voice agents, gpt-4.1, about 29k tool calls over 3 days):
\u00XXescapes\u00XXescapesSince 1.8.11, valid arguments are no longer rewritten, which removes most of this. Repaired arguments still go through
json.dumpsand still get escaped; this closes that remaining path.Test
test_execute_function_call_repaired_arguments_keep_non_ascii: a call with a missing closing brace is repaired and keeps"recepción con Martín, 東京"unescaped. It fails without the change.tests/test_tools.pyandtests/test_chat_ctx.pypass.