Skip to content

gemma4 tool parser: values truncated at commas inside lists and strings #210

Backlog

Description

@julius-huether

The VALUE state in Gemma4ToolCallParser (and _split_args in the non-streaming path) treats any comma at brace depth 0 as the end of a value.

  1. Lists: brackets aren’t counted. numbers:[1.5, 3.0] arrives as {"numbers": "[1.5"}.
  2. Strings: since the quote token <|"|> (id 52) is special and not intercepted, string values arrive unquoted, so commas inside strings end the value. An echo(text) tool called with “Hello, world, this has commas.” receives {"text": "Hello"}.

The same tests pass with Qwen3.5-family models and the qwen35 parser.

Suggested fix: count [/] like braces, and intercept token id 52 as a protocol token that toggles an “inside string” state, so commas and braces inside quotes are ignored.

Example

from openai import OpenAI

client = OpenAI(base_url="http://XYZ/v1", api_key="SECRET")
MODEL = "gemma-4-26B-A4B-it-int4"
#MODEL = "Qwen3.8-27B-int4"

TOOLS = [
    {"type": "function", "function": {
        "name": "echo",
        "description": "Echo back the given text exactly.",
        "parameters": {"type": "object",
                       "properties": {"text": {"type": "string"}},
                       "required": ["text"]}}},
    {"type": "function", "function": {
        "name": "add",
        "description": "Add a list of numbers.",
        "parameters": {"type": "object",
                       "properties": {"numbers": {"type": "array", "items": {"type": "number"}}},
                       "required": ["numbers"]}}},
]

def show_call(prompt):
    resp = client.chat.completions.create(
        model=MODEL,
        messages=[{"role": "user", "content": prompt}],
        tools=TOOLS,
        extra_body={"chat_template_kwargs": {"enable_thinking": False}},
    )
    for tc in resp.choices[0].message.tool_calls or []:
        print(f"{tc.function.name}: {tc.function.arguments}")

# Case 1: comma inside a string
# Expected: {"text": "Hello, world, this has commas."}
show_call("Use the echo tool with the text: Hello, world, this has commas.")

# Case 2: comma inside a list
# Expected: {"numbers": "[1.5, 3.0]"}
show_call("Use the add tool to add 1.5 and 3.0.")

With Gemma-4 you get:

echo: {"text": "Hello"}
add: {"numbers": "[1.5"}

With Qwen-3.8 you get:

echo: {"text": "Hello, world, this has commas."}
add: {"numbers": "[1.5, 3.0]"}

Environment

Openarc Version: Docker Image (openarc-battlemage sha-f13da14)
Model: https://huggingface.co/OpenArcBob/gemma-4-26B-A4B-it-int4-OpenArc
GPU: Arc Pro B60 running Gemma and B70 running Qwen

Disclaimer

Analysis and Example was done by Claude Opus 5.5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions