Skip to content

[Bug]: Gemini function call arguments escape non-ASCII characters as Unicode sequences #16533

@dima-hx430

Description

@dima-hx430

What happened?

Function call arguments should preserve non-ASCII characters in their original form, matching OpenAI's behavior:

{
  "function": {
    "name": "welcome_message",
    "arguments": "{\"action\":\"iPhoneやiPadなど、Apple製品についてどのようなことにお困りですか?\",\"nudge\":\"Apple製品について、テクニカルサポートに今すぐ相談可能です。\"}"
  }
}

Actual Behavior

Non-ASCII characters are escaped as Unicode sequences:

{
  "function": {
    "name": "welcome_message",
    "arguments": "{\"action\": \"iPhone\\u3084iPad\\u306a\\u3069\\u3001Apple\\u88fd\\u54c1\\u306b\\u3064\\u3044\\u3066\\u3069\\u306e\\u3088\\u3046\\u306a\\u3053\\u3068\\u3067\\u304a\\u56f0\\u308a\\u3067\\u3059\\u304b\\uff1f\", \"nudge\": \"Apple\\u88fd\\u54c1\\u306b\\u3064\\u3044\\u3066\\u3001\\u30c6\\u30af\\u30cb\\u30ab\\u30eb\\u30b5\\u30dd\\u30fc\\u30c8\\u306b\\u4eca\\u3059\\u3050\\u76f8\\u8ac7\\u53ef\\u80fd\\u3067\\u3059\\u3002\"}"
  }
}

Steps to Reproduce

  1. Make a function calling request to Gemini with non-ASCII characters in the function arguments:
import litellm

response = litellm.completion(
    model="google/gemini-2.5-flash",
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant that creates Japanese messages."
        },
        {
            "role": "user",
            "content": "apple technology"
        }
    ],
    tools=[{
        "type": "function",
        "function": {
            "name": "welcome_message",
            "description": "Creates copy for Japanese site",
            "parameters": {
                "type": "object",
                "properties": {
                    "action": {
                        "type": "string",
                        "description": "Action text in Japanese"
                    },
                    "nudge": {
                        "type": "string",
                        "description": "Nudge text in Japanese"
                    }
                },
                "required": ["action", "nudge"]
            }
        }
    }],
    tool_choice={
        "type": "function",
        "function": {"name": "welcome_message"}
    }
)

Check the function arguments

function_call = response.choices[0].message.tool_calls[0].function
print(function_call.arguments)  # Will contain \u3084 instead of や2. Observe that the `arguments` field contains escaped Unicode sequences instead of the original Japanese characters.

Relevant log output

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.77.7

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions