fix(workflow): preserve non-ASCII characters in LLM agent node input#6282
Open
anneheartrecord wants to merge 1 commit into
Open
fix(workflow): preserve non-ASCII characters in LLM agent node input#6282anneheartrecord wants to merge 1 commit into
anneheartrecord wants to merge 1 commit into
Conversation
Node input passed to an LLM agent (workflow node input and delegated-task function-call args) was serialized with json.dumps' default ensure_ascii=True, escaping non-Latin characters to \uXXXX. This bloats prompt tokens and degrades model responses for non-English inputs. Serialize with ensure_ascii=False so characters reach the model as-is, matching how the output-schema path already serializes responses.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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
input_schemainputs containing non-Latin characters (Hebrew, Chinese, etc.) reach the LLM as\uXXXXescapes, which bloats prompt tokens (~6x for Hebrew) and degrades model responses, as reported in #6279.The escaping comes from
json.dumpsbeing called with its defaultensure_ascii=Trueon the LLM-bound input text. Two paths were affected:workflow/_llm_agent_wrapper.py–_node_input_to_content()fordict/listnode input.flows/llm_flows/contents.py–_build_task_input_user_content(), which rebuilds a delegated task's function-call args as the sub-agent's first user turn. This path takes priority over the wrapper fallback, so it affects the common chat/root → task sub-agent delegation case.Both now serialize with
ensure_ascii=False, matching how the output-schema path already serializes responses (_output_schema_processor.py), fixed earlier in #2936/#2937.Note: the
BaseModelbranch (model_dump_json()) is intentionally left unchanged — Pydantic v2 already emits raw UTF-8 (does not escape non-ASCII), which the added regression test confirms.Testing
tests/unittests/workflow/test_llm_agent_as_node.py–dict/list/BaseModelnode input preserves non-ASCII.tests/unittests/flows/llm_flows/test_contents.py– delegated task FC args preserve non-ASCII.Both new tests fail before the change and pass after.
Fixes #6279