Skip to content

Conversation

nauyiahc
Copy link
Contributor

@nauyiahc nauyiahc commented May 7, 2025

  1. Updated _safe_json_serialize to use json.dumps(obj, ensure_ascii=False). This allows non-ASCII characters to be preserved in JSON output, improving readability and compatibility for internationalization.
    Addresses Non-ASCII characters (for example, Chinese characters) in tool responses are escaped before being sent to the LLM. #472

  2. The Function class's arguments field accepts a JSON string instead of a raw JSON object. This change ensures stability and handles non-ASCII characters correctly, making the arguments more robust and easier to serialize.

Copy link

google-cla bot commented May 7, 2025

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.

Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly.
@DeanChensj DeanChensj added the models [Component] Issues related to model support label May 7, 2025
@boyangsvl boyangsvl requested a review from selcukgun May 8, 2025 06:11
@boyangsvl
Copy link
Collaborator

I don't know if ensure_ascii is the problem. Ideally even if Chinese character is encoded in dumps(), once you loads() it should restore back to the correct characters.

@nauyiahc
Copy link
Contributor Author

nauyiahc commented May 8, 2025

I don't know if ensure_ascii is the problem. Ideally even if Chinese character is encoded in dumps(), once you loads() it should restore back to the correct characters.

The input to the LLM is a JSON string. I think setting ensure_ascii=False would help the LLM handle non-ASCII responses better.

@selcukgun
Copy link
Collaborator

Assuming this is useful for logging purposes (regarding json.loads not needing this).

@selcukgun selcukgun added the ready to pull [Status] This PR is ready to be importing back to Google label May 28, 2025
copybara-service bot pushed a commit that referenced this pull request May 28, 2025
--
50b09bb by Yuan Chai <350365422@qq.com>:

fix: improve json serialization by allowing non-ascii characters
--
c66977a by Yuan Chai <350365422@qq.com>:

fix: serialize function call arguments to JSON string

Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly.

COPYBARA_INTEGRATE_REVIEW=#605 from nauyiahc:fix_non_ascii_char a52513c
PiperOrigin-RevId: 764396496
@selcukgun
Copy link
Collaborator

merged by copybara: c4cd180

@selcukgun selcukgun closed this May 28, 2025
raflFaisal pushed a commit to raflFaisal/adk-python that referenced this pull request May 28, 2025
--
50b09bb by Yuan Chai <350365422@qq.com>:

fix: improve json serialization by allowing non-ascii characters
--
c66977a by Yuan Chai <350365422@qq.com>:

fix: serialize function call arguments to JSON string

Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly.

COPYBARA_INTEGRATE_REVIEW=google#605 from nauyiahc:fix_non_ascii_char a52513c
PiperOrigin-RevId: 764396496
whhlct pushed a commit to whhlct/adk-python that referenced this pull request Jun 6, 2025
--
50b09bb by Yuan Chai <350365422@qq.com>:

fix: improve json serialization by allowing non-ascii characters
--
c66977a by Yuan Chai <350365422@qq.com>:

fix: serialize function call arguments to JSON string

Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly.

COPYBARA_INTEGRATE_REVIEW=google#605 from nauyiahc:fix_non_ascii_char a52513c
PiperOrigin-RevId: 764396496
coder-aditi pushed a commit to coder-aditi/adk-python that referenced this pull request Jul 2, 2025
--
50b09bb by Yuan Chai <350365422@qq.com>:

fix: improve json serialization by allowing non-ascii characters
--
c66977a by Yuan Chai <350365422@qq.com>:

fix: serialize function call arguments to JSON string

Previously accepted JSON objects directly, which was less robust. Now serialize arguments to JSON strings using `_safe_json_serialize`, ensuring stability and handling non-ASCII characters correctly.

COPYBARA_INTEGRATE_REVIEW=google#605 from nauyiahc:fix_non_ascii_char a52513c
PiperOrigin-RevId: 764396496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
models [Component] Issues related to model support ready to pull [Status] This PR is ready to be importing back to Google
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants