Skip to content

Conversation

amenegola
Copy link

Closes #2936

This Pull Request addresses the issue where LlmAgent outputs, when configured with output_schema and tools, were presenting escaped Latin characters (e.g., \xf3 for ó) in the final response. This behavior occurred because json.dumps was being called with ensure_ascii=True (its default), which is not ideal for human-readable output, especially when dealing with non-ASCII characters common in many languages like Portuguese.

Changes Proposed:

  • Modified the _OutputSchemaRequestProcessor in src/google/adk/flows/llm_flows/_output_schema_processor.py to explicitly set ensure_ascii=False when calling json.dumps for the set_model_response tool's output.

Impact:

This change ensures that all non-ASCII characters in the structured model response are preserved in their natural form, improving the readability and user experience of agent outputs, particularly for users interacting in languages with accented characters or other special symbols.

Testing:

The fix was verified locally by running an LlmAgent with an output_schema and confirming that responses containing Latin characters (e.g., "ação", "caminhão", "ícone") are now correctly displayed without escaping.

Copy link

google-cla bot commented Sep 12, 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @amenegola, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where Latin characters were being unnecessarily escaped in LLM agent responses, particularly when an output schema was defined. By adjusting the json.dumps serialization to explicitly allow non-ASCII characters, the change significantly improves the readability and user experience for outputs in languages that utilize accented characters or special symbols.

Highlights

  • Latin Character Escaping Fix: Addresses an issue where LlmAgent outputs were incorrectly escaping Latin characters (e.g., "\xf3" for "ó") when using output_schema and tools, by explicitly setting ensure_ascii=False in json.dumps.
  • Improved Readability: Ensures that non-ASCII characters in structured model responses are preserved in their natural form, enhancing readability for languages with accented characters and special symbols.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot
Copy link
Collaborator

adk-bot commented Sep 13, 2025

Response from ADK Triaging Agent

Hello @amenegola, thank you for creating this PR!

It looks like you haven't signed the Contributor License Agreement (CLA) yet. Please visit https://cla.developers.google.com/ to sign it.

Once the CLA is signed, we can proceed with the review of your PR. Thanks!

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses the issue of escaped Latin characters in LLM responses by setting ensure_ascii=False in the json.dumps call. The change is simple and effective. My main feedback is to add an automated unit test to cover this specific case with non-ASCII characters, which will help prevent future regressions. While you've mentioned local testing, incorporating it into the test suite would be a valuable addition for long-term maintainability.

@amenegola amenegola force-pushed the fix/issue-2936-escape-chars branch 3 times, most recently from da4da5f to a7017b9 Compare September 15, 2025 14:52
@amenegola amenegola force-pushed the fix/issue-2936-escape-chars branch from a7017b9 to f99c463 Compare September 15, 2025 14:54
@amenegola
Copy link
Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses the issue of escaped Latin characters in LLM responses by setting ensure_ascii=False during JSON serialization. The fix is direct and effective. The addition of a new unit test is also great for verifying this behavior. I've added one suggestion to enhance the new test case by parameterizing it, which will improve its robustness and make it easier to extend with more scenarios in the future. Overall, this is a solid contribution.

@amenegola
Copy link
Author

@seanzhou1023 Please could you review this PR? Thank you!!!

@seanzhou1023
Copy link
Collaborator

could you run autoformat.sh to resolve the format error.

@amenegola
Copy link
Author

could you run autoformat.sh to resolve the format error.

Yes I can, should I create a new PR to correct the formatting?

@seanzhou1023 seanzhou1023 added the ready to pull [Status] This PR is ready to be importing back to Google label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

set_model_response escape latin characters in final response
3 participants