Skip to content

fix(llm): keep non-ascii text readable in mcp results and task group tool description - #7565

Merged
davidzhao merged 1 commit into
livekit:mainfrom
avionicharshit-byte:keep-non-ascii-llm-text
Oct 3, 2026
Merged

davidzhao merged 1 commit into
livekit:mainfrom
avionicharshit-byte:keep-non-ascii-llm-text

Conversation

@avionicharshit-byte

Copy link
Copy Markdown
Contributor

two places still put text into the llm context through json.dumps with the default ensure_ascii=True, so hindi (or any non-ascii text) reaches the model as \uXXXX escapes:

  • llm/mcp.py _default_tool_result_resolver: an mcp tool result with 2+ content items. the single-item path uses model_dump_json() and keeps the text readable, so the same tool output looks different depending on how many items it returns.
  • beta/workflows/task_group.py _build_out_of_scope_tool: task descriptions are embedded in the out_of_scope tool description, so "ईमेल पता पूछें" becomes "ईमेल ...".

escaped text is harder for the model to read and costs more tokens (one short hindi sentence: 104 tokens escaped vs 19 readable, o200k_base). #2622 already turned ensure_ascii off for logging; this does the same for these two llm-facing paths.

tests: tests/test_llm_text_non_ascii.py, both fail on main and pass with the fix. unit suite passes (9 test_room.py errors need a local livekit-server, same on main), make type-check clean.

@avionicharshit-byte
avionicharshit-byte marked this pull request as ready for review October 1, 2026 09:02
@avionicharshit-byte
avionicharshit-byte requested a review from a team as a code owner October 1, 2026 09:02

@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

@avionicharshit-byte

Copy link
Copy Markdown
Contributor Author

@longcw same ensure_ascii gap #2622 fixed for logs, in two places that still send text to the llm: multi-item mcp results and the task group tool description.

@davidzhao davidzhao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lg

@davidzhao
davidzhao merged commit cce33e2 into livekit:main Oct 3, 2026
20 checks passed
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