Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/google/adk/flows/llm_flows/_output_schema_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +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)
return json.dumps(func_response.response, ensure_ascii=False)

return None

Expand Down
33 changes: 33 additions & 0 deletions tests/unittests/flows/llm_flows/test_output_schema_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,39 @@ 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."""
Expand Down