[GH-ISSUE #12017] Tool call parsing fails if an argument contains a closing brace #7980

Closed
opened 2026-04-12 20:10:08 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @arcusmaximus on GitHub (Aug 21, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/12017

What is the issue?

If the LLM generates a tool call with a } character in one of the arguments, Ollama doesn't notice that it's inside a string and treats it as an end-of-object marker. It stops reading the tool call too soon, tries to parse incomplete JSON, and responds as if there's no tool call at all.

Example call to /api/chat:

{
    "model": "llama3.2",
    "messages": [{
        "role": "user",
        "content": "Output a log message consisting of the text '}A'."
    }],
    "tools": [{
        "type": "function",
        "function": {
            "name": "write_log",
            "description": "Output a log message",
            "parameters": {
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string",
                        "description": "The message to output"
                    }
                },
                "required": ["message"]
            }
        }
    }],
    "stream": false
}

This produces the following response:

{
    "message": {
        "role": "assistant",
        "content": "{\"name\": \"write_log\", \"parameters\": {\"message\": \"}A\"}}"
    },
    // ...
}

If you change the prompt to request a log message of just 'A', the tool call gets picked up correctly:

{
    "message": {
        "role": "assistant",
        "content": "",
        "tool_calls": [{
                "function": {
                    "name": "write_log",
                    "arguments": {
                        "message": "A"
                    }
                }
            }
        ]
    }
}

Relevant log output


OS

Windows

GPU

Nvidia

CPU

Intel

Ollama version

0.11.6

Originally created by @arcusmaximus on GitHub (Aug 21, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/12017 ### What is the issue? If the LLM generates a tool call with a `}` character in one of the arguments, Ollama doesn't notice that it's inside a string and treats it as an end-of-object marker. It stops reading the tool call too soon, tries to parse incomplete JSON, and responds as if there's no tool call at all. Example call to /api/chat: ```json { "model": "llama3.2", "messages": [{ "role": "user", "content": "Output a log message consisting of the text '}A'." }], "tools": [{ "type": "function", "function": { "name": "write_log", "description": "Output a log message", "parameters": { "type": "object", "properties": { "message": { "type": "string", "description": "The message to output" } }, "required": ["message"] } } }], "stream": false } ``` This produces the following response: ```jsonc { "message": { "role": "assistant", "content": "{\"name\": \"write_log\", \"parameters\": {\"message\": \"}A\"}}" }, // ... } ``` If you change the prompt to request a log message of just `'A'`, the tool call gets picked up correctly: ```json { "message": { "role": "assistant", "content": "", "tool_calls": [{ "function": { "name": "write_log", "arguments": { "message": "A" } } } ] } } ``` ### Relevant log output ```shell ``` ### OS Windows ### GPU Nvidia ### CPU Intel ### Ollama version 0.11.6
GiteaMirror added the bug label 2026-04-12 20:10:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#7980