Skip to content

Tools with output schema return Unicode characters as escaped sequences #2879

@Tomoki-Iino

Description

@Tomoki-Iino

Please make sure you read the contribution guide and file the issues in the right place.
Contribution guide.

Describe the bug
When using tools together with output_schema, Unicode characters (especially non-English languages like Japanese and Chinese) are returned as escaped Unicode sequences instead of their actual Unicode representation. This makes the output unreadable for international users.

To Reproduce
Steps to reproduce the behavior:

  1. Create an agent with both tools and output_schema
  2. Use a tool that returns Unicode text (Japanese/Chinese characters)
  3. Run the agent and observe the output
  4. See Unicode characters escaped as \uXXXX sequences

Reproduction code:

from google.adk.agents.llm_agent import LlmAgent
from google.adk.tools.tool_context import ToolContext
from google.adk.sessions.in_memory_session_service import InMemorySessionService
from google.adk.runners import Runner
from google.genai import types
from pydantic import BaseModel, Field

class Response(BaseModel):
    greeting: str = Field(description="greeting")

async def hello_tool(tool_context: ToolContext):
    """
    Tools to return greetings
    """
    return {"answer": "こんにちは"}  # Hello!

root_agent = LlmAgent(
    model='gemini-2.5-flash',
    name='root_agent',
    description='greeting agent',
    tools=[hello_tool],
    output_schema=Response,
)

app_name = "demo"
user_id = "user-01"
session_id = "session-01"

session_service = InMemorySessionService()
session = await session_service.create_session(app_name=app_name, user_id=user_id, session_id=session_id)

runner = Runner(
    app_name=app_name,
    agent=root_agent,
    session_service=session_service
)

new_message = types.Content(
    parts=[
        types.Part(text="こんにちは!元気ですか?")  # Hello! How are you?
    ],
    role="user"
)

async for event in runner.run_async(user_id=user_id, session_id=session_id, new_message=new_message):
    pass

print(event)  # the output is described below

Expected behavior
Unicode characters should be preserved in their original form:

  • Japanese: {"greeting": "こんにちは"}

Actual behavior
Unicode characters are escaped as sequences:

Event(
    content=Content(
        parts=[
            Part(
                text='{"greeting": "\\u4f60\\u597d\\u5417\\uff01"}'
            ),
        ],
        role='model'
    ),
    # ... (other fields omitted)
)

Desktop (please complete the following information):

  • OS: Linux
  • Python version(python -V): Python 3.12.3
  • ADK version(pip show google-adk): Version: 1.13.0

Model Information:
gemini-2.5-flash

Additional context
Root Cause: In src/google/adk/flows/llm_flows/_output_schema_processor.py line 110, json.dumps(func_response.response)
uses default ensure_ascii=True, which escapes non-ASCII characters.

Proposed Fix: Change to json.dumps(func_response.response, ensure_ascii=False)

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementationhelp wanted[Community] Extra attention is needed

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions