Skip to content

fix(llm): keep non-ASCII text readable in repaired tool-call arguments - #8450

Open
notarbotdev wants to merge 1 commit into
livekit:mainfrom
notarbot-com:fix/repaired-args-keep-non-ascii
Open

notarbotdev wants to merge 1 commit into
livekit:mainfrom
notarbot-com:fix/repaired-args-keep-non-ascii

Conversation

@notarbotdev

Copy link
Copy Markdown

What

_repaired_arguments_json writes repaired tool-call arguments back to the chat history with json.dumps(args_dict, default=str). The default ensure_ascii=True turns every non-ASCII character into a \uXXXX escape, 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):

Past tool calls in history Calls with garbled escapes
no \u00XX escapes 2 / 21,817 (0.01 %)
with \u00XX escapes 251 / 7,130 (3.5 %)

Since 1.8.11, valid arguments are no longer rewritten, which removes most of this. Repaired arguments still go through json.dumps and 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.py and tests/test_chat_ctx.py pass.

_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
notarbotdev requested a review from a team as a code owner November 8, 2026 00:26
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants