[GH-ISSUE #12884] error parsing tool call ... raw=... err=invalid character ... after top-level value after request to gpt-oss via api/chat #55051

Open
opened 2026-04-29 08:15:09 -05:00 by GiteaMirror · 8 comments
Owner

Originally created by @konsulll on GitHub (Oct 31, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/12884

What is the issue?

There is a problem when using tool calls via api/chat:

curl http://localhost:11434/api/chat -d '{
    "model": "gpt-oss:20b",
    "messages": [
        {
            "role": "user",
            "content": "devide 54354 by 9943 using tools\n"
        }
    ],
    "stream": true,
    "options": {
        "temperature": 0.1
    },
    "format": "json",
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "python",
                "description": "Execute arbitrary Python code with 'eval' and return result. ",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "code": {
                            "type": "string",
                            "description": "Python code to execute"
                        }
                    },
                    "required": [
                        "code"
                    ]
                }
            }
        }
    ]
}
'

that lead to :

streamed output 
...
{"model":"gpt-oss:20b","created_at":"2025-10-31T12:42:29.957861333Z","message":{"role":"assistant","content":"","thinking":"."},"done":false}
{"error":"error parsing tool call: raw='54354/9943', err=invalid character '/' after top-level value"}

Relevant log output


OS

Linux

GPU

Intel

CPU

AMD

Ollama version

0.12.6

Originally created by @konsulll on GitHub (Oct 31, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/12884 ### What is the issue? There is a problem when using tool calls via api/chat: ``` curl http://localhost:11434/api/chat -d '{ "model": "gpt-oss:20b", "messages": [ { "role": "user", "content": "devide 54354 by 9943 using tools\n" } ], "stream": true, "options": { "temperature": 0.1 }, "format": "json", "tools": [ { "type": "function", "function": { "name": "python", "description": "Execute arbitrary Python code with 'eval' and return result. ", "parameters": { "type": "object", "properties": { "code": { "type": "string", "description": "Python code to execute" } }, "required": [ "code" ] } } } ] } ' ``` that lead to : ``` streamed output ... {"model":"gpt-oss:20b","created_at":"2025-10-31T12:42:29.957861333Z","message":{"role":"assistant","content":"","thinking":"."},"done":false} {"error":"error parsing tool call: raw='54354/9943', err=invalid character '/' after top-level value"} ``` ### Relevant log output ```shell ``` ### OS Linux ### GPU Intel ### CPU AMD ### Ollama version 0.12.6
GiteaMirror added the bug label 2026-04-29 08:15:09 -05:00
Author
Owner

@ryanmon1 commented on GitHub (Oct 31, 2025):

Same issue here on all cloud models

<!-- gh-comment-id:3473996349 --> @ryanmon1 commented on GitHub (Oct 31, 2025): Same issue here on all cloud models
Author
Owner

@konsulll commented on GitHub (Nov 1, 2025):

A similar problem, but the error is different. Probably need to escape incorrect raw value characters:

curl http://localhost:11434/api/chat -d '{
    "model": "gpt-oss:20b",
    "messages": [
        {
            "role": "user",
            "content": "send to python tool string '#BVER' and return result\n"
        }
    ],
    "stream": true,
    "options": {
        "temperature": 0.1
    },
    "format": "json",
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "python",
                "description": "Execute arbitrary Python code with 'eval' and return result. ",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "code": {
                            "type": "string",
                            "description": "Python code to execute"
                        }
                    },
                    "required": [
                        "code"
                    ]
                }
            }
        }
    ]
}
'

output is:

{"error":"error parsing tool call: raw='#BVER', err=invalid character '#' looking for beginning of value"}

Another one, we send 'print' to tool:

{"error":"error parsing tool call: raw='print(\"Hello, world!\")\n', err=invalid character 'p' looking for beginning of value"}

Another example, not related to 'raw', but with hidden value:

{'error': "error parsing tool call: raw='frontendDB\n', err=invalid character 'r' in literal false (expecting 'a')"}

Result independent from "format": "json"' in request or not.

<!-- gh-comment-id:3475912497 --> @konsulll commented on GitHub (Nov 1, 2025): A similar problem, but the error is different. Probably need to escape incorrect raw value characters: ``` curl http://localhost:11434/api/chat -d '{ "model": "gpt-oss:20b", "messages": [ { "role": "user", "content": "send to python tool string '#BVER' and return result\n" } ], "stream": true, "options": { "temperature": 0.1 }, "format": "json", "tools": [ { "type": "function", "function": { "name": "python", "description": "Execute arbitrary Python code with 'eval' and return result. ", "parameters": { "type": "object", "properties": { "code": { "type": "string", "description": "Python code to execute" } }, "required": [ "code" ] } } } ] } ' ``` output is: ``` {"error":"error parsing tool call: raw='#BVER', err=invalid character '#' looking for beginning of value"} ``` Another one, we send 'print' to tool: ``` {"error":"error parsing tool call: raw='print(\"Hello, world!\")\n', err=invalid character 'p' looking for beginning of value"} ``` Another example, not related to 'raw', but with hidden value: ``` {'error': "error parsing tool call: raw='frontendDB\n', err=invalid character 'r' in literal false (expecting 'a')"} ``` Result independent from "format": "json"' in request or not.
Author
Owner

@paztis commented on GitHub (Jan 23, 2026):

Same for me frequently when llm do big tool call.
err=unexpected end of JSON input
last closing } is missing

Is it a problem of the parser or is it a real LLM problem ?

<!-- gh-comment-id:3790282334 --> @paztis commented on GitHub (Jan 23, 2026): Same for me frequently when llm do big tool call. err=unexpected end of JSON input last closing } is missing Is it a problem of the parser or is it a real LLM problem ?
Author
Owner

@paztis commented on GitHub (Jan 23, 2026):

I try a workaround: I catch the error and send a fake tool response that inform of the error and it tries again and again to redo its tool call.

At the end it even count the opening / closing braces and it is ok

The error seems really to be at the templating level or at the parsing level

Here is my error

error parsing tool call: raw='{"method":"GET","msId":"MS_17249986790420000","operation":{"operationId":"getUser","parameters":[{"name":"Authorization","in":"header","required":true,"schema":{"type":"string"}} ,{"name":"user_id","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"email":{"type":"string"}},"required":["name","email"]}}}},"404":{"description":"Not Found","content":{"application/json":{"schema":{"$ref":"datasourceId:DataSource_17250027618220000#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"datasourceId:DataSource_17250027618220000#/components/schemas/Error"}}}}}},"path":"/user"}',
err=unexpected end of JSON input

It is not a so big json

<!-- gh-comment-id:3791085577 --> @paztis commented on GitHub (Jan 23, 2026): I try a workaround: I catch the error and send a fake tool response that inform of the error and it tries again and again to redo its tool call. At the end it even count the opening / closing braces and it is ok The error seems really to be at the templating level or at the parsing level Here is my error ``` error parsing tool call: raw='{"method":"GET","msId":"MS_17249986790420000","operation":{"operationId":"getUser","parameters":[{"name":"Authorization","in":"header","required":true,"schema":{"type":"string"}} ,{"name":"user_id","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"email":{"type":"string"}},"required":["name","email"]}}}},"404":{"description":"Not Found","content":{"application/json":{"schema":{"$ref":"datasourceId:DataSource_17250027618220000#/components/schemas/Error"}}}},"500":{"description":"Internal Server Error","content":{"application/json":{"schema":{"$ref":"datasourceId:DataSource_17250027618220000#/components/schemas/Error"}}}}}},"path":"/user"}', err=unexpected end of JSON input ``` It is not a so big json
Author
Owner

@abhijeetsharma7 commented on GitHub (Feb 5, 2026):

getting same issue
for tasks which use jsons and do tool call i frequently get
error parsing tool call: raw='{".......=unexpected end of JSON input

<!-- gh-comment-id:3853767583 --> @abhijeetsharma7 commented on GitHub (Feb 5, 2026): getting same issue for tasks which use jsons and do tool call i frequently get error parsing tool call: raw='{".......=unexpected end of JSON input
Author
Owner

@ParthSareen commented on GitHub (Feb 10, 2026):

Hey folks - is this only when you update the temperature? The model is pretty sensitive to that. I'd eliminate that as a variable first.

<!-- gh-comment-id:3875069752 --> @ParthSareen commented on GitHub (Feb 10, 2026): Hey folks - is this only when you update the temperature? The model is pretty sensitive to that. I'd eliminate that as a variable first.
Author
Owner

@paztis commented on GitHub (Feb 10, 2026):

Is there's any way for us to log / dump anything to help you to resolve it ?

<!-- gh-comment-id:3875869061 --> @paztis commented on GitHub (Feb 10, 2026): Is there's any way for us to log / dump anything to help you to resolve it ?
Author
Owner

@paztis commented on GitHub (Feb 13, 2026):

I provide a reproduction case here for me https://github.com/ollama/ollama/pull/14180#issuecomment-3896927990

<!-- gh-comment-id:3896935176 --> @paztis commented on GitHub (Feb 13, 2026): I provide a reproduction case here for me https://github.com/ollama/ollama/pull/14180#issuecomment-3896927990
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#55051