Local chat works, but your llama.cpp script prints role markers
If the same GGUF answers normally in chat but your script echoes the question or prints `<|im_start|>`, check whether your script is formatting the conversation twice. Preview the exact messages before changing the model or its settings.
Find out who formats your chat messages
A chat template marks which lines belong to the user and where the model’s reply begins. With llama.cpp’s /v1/chat/completions route, send the conversation as messages: give each message a role and put ordinary message text in content. The server applies its configured template. By contrast, llama.cpp’s native /completion takes a single prompt string for continuation. Moving a preformatted string from a raw-prompt example into a chat message can put a second set of role markers around the same question.
Use the working build as your control
Keep the same local llama.cpp server and GGUF you already loaded. For a concrete reference, Qwen publishes qwen2.5-1.5b-instruct-q4_k_m.gguf at revision 91cad51. The publisher’s separate tokenizer config for Qwen2.5-1.5B-Instruct, revision 5fee7c4, shows <|im_start|> and <|im_end|> around messages, and adds the assistant header when generation is requested. That file describes the publisher’s format. It does not tell you whether your running server uses it unchanged or the script has already added it.
Preview one message without generating an answer
Only if your already-running llama.cpp server is bound to 127.0.0.1 and its version documents this route (verified in b9860), send the fictional JSON body to POST /apply-template on that existing local address, without the /v1 prefix. The returned JSON prompt is what the server prepared, not a model answer. If the route is absent, inspect the script’s outgoing messages without sending them. Do not use private text or a shared or hosted server for this test.
{
"messages": [
{
"role": "user",
"content": "Reply with the name of one blue fruit."
}
]
}Compare that preview with a second one using your script’s outgoing messages, with the same fictional question in place of real text. If the script has already added <|im_start|>user or <|im_end|> inside content, those are not the markers the server adds around the message. A second set around that one question in the rendered prompt is evidence of double formatting. The server may also add a system message on its own; multiple markers in the whole preview are not enough to diagnose the problem.
Fix the extra formatting in the script, not in the GGUF
If you found the extra layer, keep the chat endpoint and pass the plain sentence in content. Remove the script’s manual wrapper, not the model’s configured template. Preview the request again and check that the pretend question sits in a single user turn. If the route is missing in your build, inspect the script’s outgoing messages with the same harmless example; don’t expose the server just to make the check work. If both prompts look the same and the bad reply persists, this test has not identified the cause. Don’t redownload the model or change stop tokens on the strength of role markers alone.
Sources
- llama.cpp · DocumentationPublisher · github.com↗
- llama.cpp · DocumentationPublisher · github.com↗
- llama.cpp · DocumentationPublisher · github.com↗
- Hugging Face · DocumentationPublisher · huggingface.co↗
- Hugging Face · DocumentationPublisher · huggingface.co↗
- Hugging Face · DocumentationPublisher · huggingface.co↗