# Why does my model ramble or answer itself?

> Every model expects a specific wrapper around each message, called a chat template. Get it wrong and the model rambles, talks to itself or prints stray tags.

Usually because the chat template is wrong. A chat model was trained on conversations wrapped in special markers, and it only behaves when it sees the same markers again. Use a runtime that reads the template from the model file and most of these problems disappear.

## Models expect a wrapper

A model does not see a chat. It sees one long string of text. The chat template turns your messages into that string, with markers that say who is speaking and where each turn ends.

Here is one short exchange in the ChatML format, which several model families use.

```text
<|im_start|>system
You are a concise assistant.<|im_end|>
<|im_start|>user
What is a token?<|im_end|>
<|im_start|>assistant
```

The string ends with the start of an assistant turn. The model fills it in, then writes `<|im_end|>` when it is done. The runtime watches for that marker and stops.

Other families use different markers for the same job. Llama, Gemma, Mistral and gpt-oss each have their own. The markers are special [What is a token?](https://localagi.co/tokens), learned in training, so a model only understands its own.

**Rule of thumb.** 
Let the runtime use the template stored in the model file. Only set one by hand when the output shows the symptoms below.

## Symptoms of a wrong template

A wrong template rarely causes an error. The model still runs and writes text. It just behaves strangely, and the cause is easy to miss.

| Symptom | What is going on |
| --- | --- |
| Rambling that never stops | The runtime does not know the stop marker, so it never ends the turn |
| The model writes your next message, then answers it | It does not see a turn boundary and carries on the conversation alone |
| Stray tags in the output, such as `<\|im_end\|>` or `[INST]` | Markers from the wrong format are being printed as text |
| Ignores the system prompt | The system message is wrapped in a way the model was not trained on |
| Fine for one message, odd after several | The template handles history differently from what the model expects |

[Why is the output nonsense?](https://localagi.co/nonsense-output) covers other causes of bad output, such as a corrupted download or the wrong [Should I touch temperature and the other sliders?](https://localagi.co/sampling) settings. Check the template first, because it is the most common one with new models.

### How to fix it

GGUF files carry their template inside them. [Ollama](https://localagi.co/ollama), [LM Studio](https://localagi.co/lm-studio) and [llama.cpp](https://localagi.co/llama-cpp) read it automatically in current versions. For llama.cpp's server, the `--jinja` flag tells it to use that embedded template in full.

```bash
llama-server -m model.gguf --jinja
```

If the template inside the file is wrong, download the model from a different uploader. Upload quality varies, and a broken template is one of the common faults. [Where do I download models?](https://localagi.co/where-models-come-from) covers how to pick one.

**The catch.** 
A new model can arrive before runtimes fully support its template. Tool calls and thinking tags are the usual weak spots in the first weeks. If a brand-new model misbehaves, update the runtime before you blame the model.

## System prompts

The system prompt is the first message in the conversation. It sets standing instructions: the role, the tone, the format, the rules. The model gives it more weight than a normal message because it was trained that way.

Use it for things that hold for the whole conversation. "Answer in British English." "Reply in under 100 words unless asked." "You are reviewing Python code for a team that uses type hints." Put the task itself in the user message.

### How long is too long

Every token of the system prompt is read on every request and takes space in the [How much can the model keep in mind?](https://localagi.co/context-window). A few hundred tokens costs almost nothing. A few thousand starts to matter on a small context, and agents often ship system prompts that size.

Length also hurts accuracy on small models. A 4B model given 40 rules will follow some and forget others. Keep it short and specific, and test each rule actually changes the output.

**Try it.** 
See the template your model uses in Ollama.

```bash
ollama show qwen3:8b --template
```

The output is the template with placeholders for the system prompt and messages. Compare its markers with any stray tags you see in answers.

## Go deeper

### Templates are code

Most templates are written in Jinja, a small templating language. They loop over the messages, insert markers, and handle special cases such as tool calls, images and thinking. A template can be dozens of lines long, which is why a small mismatch between runtimes causes problems.

### The base model trap

Some uploads are base models, trained only to continue text and never taught to chat. They have no template at all.

Give one a question and it might write three more questions in the same style. If the name lacks words like Instruct, Chat or IT, check the model card. [How do I read a model name?](https://localagi.co/reading-model-names) explains the labels.

### Tool calls and thinking go through the template too

When an app offers the model tools, the template formats the tool list and the model's calls. When a [reasoning model](https://localagi.co/reasoning-models) thinks, the template decides where the thinking goes and whether earlier thinking is kept in the history. A template that handles plain chat correctly can still break both.
