From 0f087a49f643774ad6e5e922f7b6480492ccd791 Mon Sep 17 00:00:00 2001 From: Afonso Menegola Date: Fri, 12 Sep 2025 20:41:36 -0300 Subject: [PATCH 1/3] Fix: #2936 - Prevent escaping of Latin characters in LLM response --- src/google/adk/flows/llm_flows/_output_schema_processor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/google/adk/flows/llm_flows/_output_schema_processor.py b/src/google/adk/flows/llm_flows/_output_schema_processor.py index da793f8f9e..e00672d7e1 100644 --- a/src/google/adk/flows/llm_flows/_output_schema_processor.py +++ b/src/google/adk/flows/llm_flows/_output_schema_processor.py @@ -107,7 +107,9 @@ def get_structured_model_response(function_response_event: Event) -> str | None: for func_response in function_response_event.get_function_responses(): if func_response.name == 'set_model_response': # Convert dict to JSON string - return json.dumps(func_response.response) + return json.dumps( + func_response.response, ensure_ascii=False + ) return None From f99c463f6310f1a1e8efdca6af130ebb3556e78d Mon Sep 17 00:00:00 2001 From: Afonso Menegola Date: Mon, 15 Sep 2025 11:49:25 -0300 Subject: [PATCH 2/3] featgit status --- .../llm_flows/test_output_schema_processor.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/unittests/flows/llm_flows/test_output_schema_processor.py b/tests/unittests/flows/llm_flows/test_output_schema_processor.py index 70eedcc696..20ab3930fb 100644 --- a/tests/unittests/flows/llm_flows/test_output_schema_processor.py +++ b/tests/unittests/flows/llm_flows/test_output_schema_processor.py @@ -254,6 +254,41 @@ async def test_output_schema_helper_functions(): assert extracted_json is None +@pytest.mark.asyncio +async def test_get_structured_model_response_with_non_ascii(): + """Test get_structured_model_response with non-ASCII characters.""" + from google.adk.events.event import Event + from google.adk.flows.llm_flows._output_schema_processor import ( + get_structured_model_response, + ) + from google.genai import types + + # Test with a dictionary containing non-ASCII characters + test_dict = {'city': 'São Paulo'} + expected_json = '{"city": "São Paulo"}' + + # Create a function response event + function_response_event = Event( + author='test_agent', + content=types.Content( + role='user', + parts=[ + types.Part( + function_response=types.FunctionResponse( + name='set_model_response', response=test_dict + ) + ) + ], + ), + ) + + # Get the structured response + extracted_json = get_structured_model_response(function_response_event) + + # Assert that the output is the expected JSON string without escaped characters + assert extracted_json == expected_json + + @pytest.mark.asyncio async def test_end_to_end_integration(): """Test the complete output schema with tools integration.""" From 6cac00f97aa4cd8d8ccaa97ec5fffc74f57995dc Mon Sep 17 00:00:00 2001 From: Afonso Menegola Date: Tue, 16 Sep 2025 14:09:22 -0300 Subject: [PATCH 3/3] fix:formatting corrected after autoformat.sh --- src/google/adk/flows/llm_flows/_output_schema_processor.py | 4 +--- .../unittests/flows/llm_flows/test_output_schema_processor.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/google/adk/flows/llm_flows/_output_schema_processor.py b/src/google/adk/flows/llm_flows/_output_schema_processor.py index e00672d7e1..d8a3f47ff4 100644 --- a/src/google/adk/flows/llm_flows/_output_schema_processor.py +++ b/src/google/adk/flows/llm_flows/_output_schema_processor.py @@ -107,9 +107,7 @@ def get_structured_model_response(function_response_event: Event) -> str | None: for func_response in function_response_event.get_function_responses(): if func_response.name == 'set_model_response': # Convert dict to JSON string - return json.dumps( - func_response.response, ensure_ascii=False - ) + return json.dumps(func_response.response, ensure_ascii=False) return None diff --git a/tests/unittests/flows/llm_flows/test_output_schema_processor.py b/tests/unittests/flows/llm_flows/test_output_schema_processor.py index 20ab3930fb..a9dea8c919 100644 --- a/tests/unittests/flows/llm_flows/test_output_schema_processor.py +++ b/tests/unittests/flows/llm_flows/test_output_schema_processor.py @@ -258,9 +258,7 @@ async def test_output_schema_helper_functions(): async def test_get_structured_model_response_with_non_ascii(): """Test get_structured_model_response with non-ASCII characters.""" from google.adk.events.event import Event - from google.adk.flows.llm_flows._output_schema_processor import ( - get_structured_model_response, - ) + from google.adk.flows.llm_flows._output_schema_processor import get_structured_model_response from google.genai import types # Test with a dictionary containing non-ASCII characters