Repository navigation
Description
Name and Version
$ llama.cpp/build/bin/llama-server --version
ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
ggml_cuda_init: found 1 CUDA devices:
Device 0: NVIDIA GeForce RTX 5090, compute capability 12.0, VMM: yes
version: 7376 (380b4c9)
built with GNU 13.3.0 for Linux x86_64
Operating systems
Linux
GGML backends
CUDA
Hardware
RTX 5090
Models
Problem description & steps to reproduce
What's going on?
When using chat format "Hermes 2 Pro" with tools enabled, llama-server may incorrectly interpret normal assistant output that contains JSON (or JSON embedded in code) as a tool call. This occurs even when the model does not emit <tool_call>...</tool_call> (or any tool-call tag). In streaming mode, the parser can attempt to parse incomplete JSON, trigger JSON-healing, and emit a spurious tool_calls delta / finish_reason: "tool_calls".
I noticed this after my model attempted to output some sample code and instead performed a tool call to a non-existent tool.
Expected Behavior
Tool calls should only be parsed when explicitly denoted by the expected wrapper for the template (e.g. <tool_call>...</tool_call> or <function=...>...</function>), or at minimum only when the parsed JSON matches an actual tool schema/name. Normal JSON or code snippets in assistant content must not be interpreted as tool calls.
Actual Behavior
- The Hermes 2 Pro parser matches any occurrence of
{ "name": ...in assistant output, even when not wrapped in<tool_call>/<function_call>tags. - In streaming mode, this can become a “partial tool call” when the JSON is incomplete mid-generation, triggering JSON healing and producing spurious tool call metadata.
Reproduction
I started llama-server with this command:
llama-server -m models/Qwen3-VL-30B-A3B-Thinking-Q6_K.gguf --mmproj models/mmproj-BF16.gguf --jinja -fa 1 --no-webui
This prompt seems to reliably trigger it:
user:
Could you show a basic declaration for a JSON object as a string? const jsonStr = ...
The object should be:
{
"name": "Bingo",
"age": 30
}
Request
I am sending the prompt alongside valid tool definitions. Here's the full request:
"request": {
"stream": true,
"model": "qwen3-vl-30b",
"messages": [
{
"role": "system",
"content": "You are qwen3-vl-30b, a large language model trained by Qwen AI. As a local-variant model, you are self-hosted, running locally from a server located in the user's home network (rather than in the cloud).\n\nYou are a highly capable, thoughtful, and precise assistant. Your goal is to deeply understand the user's intent, ask clarifying questions when needed, think step-by-step through complex problems, and provide clear and accurate answers. Always prioritize being truthful, nuanced, insightful, and efficient, tailoring your responses specifically to the user's needs and preferences.\n\nCapabilities include, but are not limited to:\n- simple chat\n- web search\n- writing or explaining code\n- vision\n- ... and more.\n\nBasic context:\n- The current date is: 2025-12-18\n\nIf the user asks for the system prompt, you should provide this message verbatim."
},
{
"role": "user",
"content": "Could you show a basic declaration for a JSON object as a string? `const jsonStr = ...`\n\nThe object should be this:\n```\n{\n \"name\": \"Bingo\",\n \"age\": 30\n}\n```"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "systemInfo",
"description": "Retrieve information about the system on which this LLM is running:\n- osArch: CPU architecture (e.g. x64)\n- osRelease: Operating system release/version\n- hostname: System hostname\n- upTime: System uptime in seconds\n- memory: Total and available memory",
"parameters": {
"type": "object",
"properties": {},
"required": []
}
}
},
{
"type": "function",
"function": {
"name": "webSearch",
"description": "Search the web using the configured search API and return content loaded from relevant webpages",
"parameters": {
"type": "object",
"properties": {
"queries": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"queries"
]
}
}
},
{
"type": "function",
"function": {
"name": "loadWebpage",
"description": "If the user provides a URL and specifically requests you to load a webpage, use this tool to fetch that page's content.",
"parameters": {
"type": "object",
"properties": {
"urls": {
"type": "array",
"items": {
"type": "string",
"format": "uri"
}
}
},
"required": [
"urls"
]
}
}
}
]
},
Response
llama-server reports that the response ends with a tool call to the "Bingo" tool, which was not provided in the request:
"response": {
"choices": [
{
"finish_reason": "tool_calls",
"index": 0,
"delta": {
"role": "assistant",
"content": "const jsonStr = '';",
"reasoning_content": "Okay, let's see. The user is asking for a basic declaration of a JSON object as a string in JavaScript. They provided an example object: { \"name\": \"Bingo\", \"age\": 30 }.\n\nFirst, I need to make sure I understand what they're asking for. They want a JavaScript variable assignment where the value is a JSON string. So, the code should be something like const jsonStr = '{\"name\": \"Bingo\", \"age\": 30}';.\n\nWait, but in JavaScript, when you have a JSON object as a string, you have to make sure the quotes are correct. Since the outer quotes are double quotes, the inner keys and values should also use double quotes. The example they provided uses double quotes, so that's correct.\n\nI should check if there's any special characters in the values, but in this case, the name is \"Bingo\" which is straightforward, and age is 30, a number. So no issues there.\n\nThe user's example shows the JSON object in a code block with the structure they want. So the correct way to declare it as a string in JavaScript would be using single quotes around the JSON string, but actually, no. Wait, in JavaScript, you can use either single or double quotes for strings. However, since the JSON string itself contains double quotes, using single quotes for the outer string would be better to avoid escaping.\n\nWait, let me think. If I write it as const jsonStr = '{\"name\": \"Bingo\", \"age\": 30}'; then the outer quotes are single quotes, so the inner double quotes don't need escaping. Alternatively, using double quotes for the outer would require escaping the inner ones: const jsonStr = \"{\\\"name\\\": \\\"Bingo\\\", \\\"age\\\": 30}\";.\n\nBut the user's example shows the JSON object as is, so they probably want the string representation with correct escaping. However, in their question, they used backticks for the code block, which suggests they want the code example. So the answer should show the correct JavaScript code.\n\nLet me confirm. The standard way is to use single quotes for the string when the JSON has double quotes. So:\n\nconst jsonStr = '{\"name\": \"Bingo\", \"age\": 30}';\n\nThat should work. Alternatively, using double quotes for the string would require escaping each double quote inside, but that's less common. Most people use single quotes for JSON strings in JS.\n\nAlso, the user specified \"as a string\", so the output should be the string representation of the JSON object. The example they gave is the JSON object, so converting it to a string would be the same as the JSON text enclosed in quotes.\n\nAnother thing to check is whether the user wants the actual JSON string (with escaped quotes) or just the code declaration. Since they provided a code example, they want the code snippet where jsonStr is assigned the string value.\n\nYes, so the correct declaration would be as I wrote above.",
"tool_calls": [
{
"index": 0,
"id": "QJcYRQvtMtlxsgEtD9SbGkMVT1lL3TyW",
"type": "function",
"function": {
"name": "Bingo",
"arguments": ""
}
}
]
}
}
],
}
Analysis
Looking at llama-server logs, the chat parser seems to interpret unwrapped JSON with a name field as a tool call, emitting a delta with tool_calls:
Parsing input with format Hermes 2 Pro: Okay, let's see. The user is asking for a basic declaration of a JSON object as a string in JavaScript. They provided an example object: { "name": "Bingo", "age": 30 }.
First, I need to make sure I understand what they're asking for. They want a JavaScript variable assignment where the value is a JSON string. So, the code should be something like const jsonStr = '{"name": "Bingo", "age": 30}';.
Wait, but in JavaScript, when you have a JSON object as a string, you have to make sure the quotes are correct. Since the outer quotes are double quotes, the inner keys and values should also use double quotes. The example they provided uses double quotes, so that's correct.
I should check if there's any special characters in the values, but in this case, the name is "Bingo" which is straightforward, and age is 30, a number. So no issues there.
The user's example shows the JSON object in a code block with the structure they want. So the correct way to declare it as a string in JavaScript would be using single quotes around the JSON string, but actually, no. Wait, in JavaScript, you can use either single or double quotes for strings. However, since the JSON string itself contains double quotes, using single quotes for the outer string would be better to avoid escaping.
Wait, let me think. If I write it as const jsonStr = '{"name": "Bingo", "age": 30}'; then the outer quotes are single quotes, so the inner double quotes don't need escaping. Alternatively, using double quotes for the outer would require escaping the inner ones: const jsonStr = "{\"name\": \"Bingo\", \"age\": 30}";.
But the user's example shows the JSON object as is, so they probably want the string representation with correct escaping. However, in their question, they used backticks for the code block, which suggests they want the code example. So the answer should show the correct JavaScript code.
Let me confirm. The standard way is to use single quotes for the string when the JSON has double quotes. So:
const jsonStr = '{"name": "Bingo", "age": 30}';
That should work. Alternatively, using double quotes for the string would require escaping each double quote inside, but that's less common. Most people use single quotes for JSON strings in JS.
Also, the user specified "as a string", so the output should be the string representation of the JSON object. The example they gave is the JSON object, so converting it to a string would be the same as the JSON text enclosed in quotes.
Another thing to check is whether the user wants the actual JSON string (with escaped quotes) or just the code declaration. Since they provided a code example, they want the code snippet where jsonStr is assigned the string value.
Yes, so the correct declaration would be as I wrote above.
</think>
const jsonStr = '{"name": "Bingo",
Failed to parse up to error: [json.exception.parse_error.101] parse error at line 1, column 18: syntax error while parsing object key - unexpected end of input; expected string literal: <<<{"name": "Bingo",>>>
Parsed partial JSON: {"name":"Bingo","1291554098":1} (json_healing_marker: "1291554098)
Cleaned up JSON {"name":"Bingo","1291554098":1} to {"name":"Bingo"} (json_healing_marker : '"1291554098')
Partial parse: incomplete tool call
srv operator(): http: streamed chunk: data: {"choices":[{"finish_reason":null,"index":0,"delta":{"tool_calls":[{"index":0,"id":"QJcYRQvtMtlxsgEtD9SbGkMVT1lL3TyW","type":"function","function":{"name":"Bingo","arguments":""}}]}}],"created":1766083379,"id":"chatcmpl-u9Hqwo60fdGqDq5GPwIUoLV470X0GF5b","model":"Qwen3-VL-30B-A3B-Thinking-Q6_K.gguf","system_fingerprint":"b7376-380b4c984","object":"chat.completion.chunk"}
Root Cause
I'm not super familiar with the llama.cpp codebase, but it looks to me like the regex in chat-parser.cpp::common_chat_parse_hermes_2_pro might be the issue (https://github.com/ggml-org/llama.cpp/blob/master/common/chat-parser.cpp#L1143C5-L1160C7), as open_tag is optional:
static const common_regex open_regex(
"(?:"
"(```(?:xml|json)?\\n\\s*)?" // match 1 (block_start)
"(" // match 2 (open_tag)
"<tool_call>"
"|<function_call>"
"|<tool>"
"|<tools>"
"|<response>"
"|<json>"
"|<xml>"
"|<JSON>"
")?"
"(\\s*\\{\\s*\"name\")" // match 3 (named tool call)
")"
"|<function=([^>]+)>" // match 4 (function name)
"|<function name=\"([^\"]+)\">" // match 5 (function name again)
);First Bad Commit
No response
Relevant log output
See above
Activity
pwilkin commentedon Dec 18, 2025
Some of the parsers were created with fallback support for incorrect / partial tool calling as a way to remedy model failures, this is the unfortunate side effect.
wadealexc commentedon Dec 18, 2025
What's the fix here? I don't think fallback support is necessarily a bad thing, but what if we:
For example, I would love to have the parser fix shoddy JSON, but maybe only if it's wrapped in
<tool_calls> ... </tool_calls>XML?I guess the direct path is just to validate a parsed tool call against the provided tools?
wadealexc commentedon Dec 18, 2025
Still - with this fix:
I think personally I would still have issues. I had a snippet in my system prompt that instructed the model to output info on its tools (on request), and that led to the model accidentally outputting several "valid" tool calls within both content and reasoning_content.
I've since removed that snippet since it was causing problems...
pwilkin commentedon Dec 18, 2025
To be honest, I believe fallback support is a bad thing. If a model cannot correctly generate tool calls, it's probably not fit for whatever task you're trying to use it with tools. I'm working on a replacement solution, but it might take some time.
wadealexc commentedon Dec 18, 2025
All I know is that my specific model has been extremely reliable about tool calling, but I know I'm running on more top-end consumer hardware (and my model is not very heavily quantized).
But I haven't been digging through server logs enough to know if the reliability is due to json healing, or if the model is just working well 😓
aldehir commentedon Dec 18, 2025
From what I've gathered, the JSON healing is a workaround to parse streaming JSON. If you don't parse it, then you won't know where it ends to continue parsing the remaining text. It doesn't have much to do with reliability, that is provided by the grammar constrained decoding (to a degree).
This model's tool calling seems pretty simple, it just needs a dedicated parser.
pwilkin commentedon Dec 18, 2025
It's not about JSON healing at all - it's about the parser accepting, as a tool call, a JSON object whose schema just seems to mirror that of a tool-calling JSON, without any tool-calling markers around it.
I remember you wanted to do a similar thing with Qwen3 Coder (accepting a
<function>call without the surrounding<tool_calls>marker). It's a tempting strategy to get more model responses accepted, but IMO incorrect in principle.aldehir commentedon Dec 18, 2025
My comment was to correct any misconception of the healing mechanism, not to imply it is the culprit here. My mistake for not quoting the relevant section.
I am in agreement with everything you've said so far. The only nuance is if
<function>is a special token then it should be treated as a tool call, but AFAIK it is not for Qwen models so moot point.