Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: improve json serialization by allowing non-ascii characters #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nauyiahc wants to merge 5 commits into google:main from nauyiahc:fix_non_ascii_char

Conversation

@nauyiahc
Copy link
Contributor

@nauyiahc nauyiahc commented May 7, 2025
edited
Loading

  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
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.

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.

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
Copy link
Collaborator

merged by copybara: c4cd180

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

Reviewers

@selcukgun selcukgun selcukgun approved these changes

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /