Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 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,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

Expand Down
35 changes: 35 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,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."""
Expand Down
Loading