Ollama Modelfile: how FROM, PARAMETER, TEMPLATE and SYSTEM change what your local model receives
TL;DR: A Modelfile is the blueprint Ollama uses to build a model — FROM picks the base weights, PARAMETER sets runtime options, TEMPLATE is the prompt format, and SYSTEM is the system message. The trap that costs people an afternoon: TEMPLATE is a Go template, and if your template never mentions {{ .System }}, the system message is dropped before the model sees it. I measured this on Ollama 0.40.16 (released November 9, 2026) with four models built from the same 19 MB GGUF: with a template that omits {{ .System }}, the prompt was 19 tokens whether or not a system message was sent; with {{ .System }} in the template, the stored system message was in the prompt every time.
What you’ll be able to do:
- Read a model’s stored blueprint with
ollama show --modelfile, and the individual pieces with--template,--systemand--parameters. - Tell the difference between “my system prompt is being overridden” and “my system prompt never reached the model”.
- Recognise the three creation errors that look like something else (
invalid model name,pull model manifest: file does not exist,unknown parameter). - Build a Modelfile from a local GGUF instead of pulling a multi-gigabyte model just to test a prompt format.
Honest take: the model in this test is a 15-million-parameter story model from the llama.cpp test corpus. Its output is nonsense and the numbers say nothing about answer quality. They say exactly one thing: which tokens Ollama sent to the model.
What a Modelfile is, and what is in it
Ollama’s own reference calls a Modelfile “the blueprint to create and share customized models”. The format is deliberately small: one instruction per line, # for comments.
FROM llama3.2
PARAMETER temperature 1
PARAMETER num_ctx 4096
SYSTEM You are Mario from super mario bros, acting as an assistant.
You build it with ollama create <name> -f ./Modelfile and read it back with ollama show --modelfile <name>. The reference page, checked November 18, 2026, documents eight instructions:
| Instruction | What it does |
|---|---|
FROM (required) | The base model: a library name, a directory of safetensors weights, or a GGUF file path |
PARAMETER | A runtime option: num_ctx, temperature, top_k, top_p, min_p, seed, stop, num_predict, repeat_penalty, repeat_last_n, draft_num_predict |
TEMPLATE | The full prompt template sent to the model |
SYSTEM | The system message, used by the template |
MESSAGE | Pre-seeded message history |
LICENSE | The licence text for the model you publish |
REQUIRES | Minimum Ollama version the model needs |
CAPABILITY | Declares an extra capability (vision, tools, …) |
FROM accepts three shapes, and this matters when you are working offline. A library name pulls the model. A directory must contain safetensors weights. A GGUF file is addressed by absolute path or relative to the Modelfile’s own location, and a split model uses a wildcard:
FROM ./model-*.gguf
The bug this article is about
Everything above is in the documentation. What is not in the documentation is the size of the mistake you can make with TEMPLATE.
TEMPLATE is a Go text/template with three documented variables:
| Variable | Meaning |
|---|---|
{{ .System }} | The system message |
{{ .Prompt }} | The user prompt |
{{ .Response }} | The model’s response; text after it is omitted while generating |
If your template does not mention {{ .System }}, nothing renders the system message. Not “renders it empty” — it never enters the prompt at all.
I built four models from the same weights to measure it. The base is tinyllamas/stories15M-q4_0.gguf (19,077,344 bytes, GGUF v3, 57 tensors, llama architecture, 24.41M parameters, Q4_0, llama.context_length 128) from the llama.cpp test corpus on Hugging Face. Ollama 0.40.16, running locally on CPU. Four Modelfiles, same FROM, four templates:
# story-bare: the prompt and nothing else
TEMPLATE """{{ .Prompt }}"""
# story-nosys: role markers, but no system slot
TEMPLATE """{{ if .Prompt }}<|user|>
{{ .Prompt }}
{{ end }}<|assistant|>
"""
# story-sys: the same, with a system slot
TEMPLATE """{{ if .System }}<|system|>
{{ .System }}
{{ end }}{{ if .Prompt }}<|user|>
{{ .Prompt }}
{{ end }}<|assistant|>
"""
# story-base: no TEMPLATE at all
Then the same chat request against each one — "Name one colour.", with and without a system message — and the prompt token count Ollama reported:
| Model | Template | Prompt tokens, user only | Prompt tokens, system + user |
|---|---|---|---|
story-bare | {{ .Prompt }} | 5 | 5 |
story-nosys | user/assistant markers, no {{ .System }} | 19 | 19 |
story-sys | same template with {{ .System }} | 38 | 38 |
story-base | no TEMPLATE in the Modelfile | 31 | 59 |
Read the table twice, because the last two rows are the interesting ones.
A custom template without {{ .System }} discards the system message. story-nosys reports 19 prompt tokens for the user-only request and 19 for the system-plus-user request. Adding a system message changed nothing, because the template has nowhere to put it. story-bare is the same story in miniature: 5 tokens either way.
A template with {{ .System }} always injects the model’s stored system message. story-sys reports 38 tokens in both cases. The stored SYSTEM line from the Modelfile is what lands in the prompt; the system message supplied with the API request did not add a single token on top of it.
Omitting TEMPLATE is not the same as writing an empty one. story-base was created with no template instruction at all, and it behaves differently from story-bare: 31 prompt tokens for the user-only request, and 59 once a system message was added. Ollama applied a built-in default template for that model, and that default template does carry the system message. Write your own template and you take over a job the default was doing for you — including the job of passing the system message through.
That is the whole bug. “My agent sends a system prompt and the model ignores it” is either a rendering problem (your template has no {{ .System }}) or an override problem (your template has {{ .System }}, and the model’s stored SYSTEM wins). The two look identical from the outside, and the token counts above tell them apart in one request.
Reading the stored blueprint
ollama show has a flag per piece, which is the fastest way to find out which of the two problems you have:
$ ollama show --template story-sys
{{ if .System }}<|system|>
{{ .System }}
{{ end }}{{ if .Prompt }}<|user|>
{{ .Prompt }}
{{ end }}<|assistant|>
$ ollama show --system story-sys
You are a terse assistant that answers in one word.
$ ollama show --parameters story-sys
num_ctx 512
temperature 0
The same information is available over HTTP, which is what you want if a script is driving the server:
$ curl -s http://127.0.0.1:11434/api/show -d '{"model":"story-sys"}'
{"template":"{{ if .System }}<|system|>\n{{ .System }}\n{{ end }}...","system":"You are a terse assistant...","parameters":"num_ctx 512\ntemperature 0"}
Note what ollama show --modelfile gives you back for a model you just built:
# Modelfile generated by "ollama show"
# To build a new Modelfile based on this, replace FROM with:
# FROM story-sys:latest
FROM /root/.ollama/models/blobs/sha256-66967fbece6dbe97886593fdbb73589584927e29119ec31f08090732d1861739
TEMPLATE "{{ if .System }}<|system|>
...
SYSTEM You are a terse assistant that answers in one word.
PARAMETER num_ctx 512
PARAMETER temperature 0
Two details worth knowing. FROM comes back as a path into the blob store, because that is where the weights actually live — a round-tripped Modelfile is still valid, and the reference notes the same shape in its own ollama show --modelfile example. And PARAMETER lines come back one per setting, which is why PARAMETER stop can be repeated: each occurrence is a separate stop pattern.
If you want the same information in a form your tooling can diff, POST /api/show with {"model": "..."} returns the same three fields as JSON, which is the endpoint the metadata check article uses before a load.
Parameters that actually change behaviour
The reference lists each parameter with its default. The ones that matter most on a home-lab box:
| Parameter | Default | What it does |
|---|---|---|
num_ctx | 2048 | Context window size |
temperature | 0.8 | Sampling randomness |
top_k | 40 | Candidate limit |
top_p | 0.9 | Nucleus sampling |
min_p | 0.0 | Alternative to top_p, relative to the most likely token |
seed | 0 | Fixed sampling seed for reproducible output |
num_predict | -1 | Maximum tokens to generate; -1 means unlimited |
stop | — | Stop sequences; repeat the instruction for more than one |
repeat_penalty | 1.0 | Repetition penalty |
repeat_last_n | 64 | How far back the repetition check looks |
draft_num_predict | 4 | Draft tokens per step when a draft model is available; 0 disables it |
Two of these are worth calling out for a local setup. num_ctx is a per-model default, and Ollama’s own runtime default is not always the same number — the server log prints the value it picked ("vram-based default context" ... default_num_ctx=4096 on a CPU-only box), so if you need a specific context, set it in the Modelfile instead of relying on the server default. And seed is the parameter that makes a local run reproducible, which is what you want when you are comparing two prompt formats.
One caveat, measured rather than assumed: the test model reports llama.context_length 128 in its GGUF metadata, and the generated token counts came back identical across all four variants regardless of the num_ctx 512 I set. The parameter is stored and reported; how much of it the runtime honours is bounded by what the weights support. Set it on a real model, and check /api/show to confirm it stuck.
The three creation errors you will actually hit
All three of these came out of the same session, and none of them says what is wrong.
A FROM path that does not exist:
$ ollama create abs-test -f Modelfile.abs
Error: 400 Bad Request: invalid model name
invalid model name is misleading — the name is fine, the file is missing. The same command with a relative path that does resolve works, because a relative FROM is resolved against the Modelfile’s directory. Check the path first when you see this error.
A FROM name that is not in the library and cannot be pulled:
$ ollama create name-test -f Modelfile.name
Error: pull model manifest: file does not exist
This one is at least honest: the name was treated as a library reference, so Ollama tried to pull it. If you meant a local file, use a path.
A parameter that does not exist:
$ ollama create param-test -f Modelfile.param
Error: unknown parameter 'nonsense_param'
Good error, and worth reading carefully: Ollama rejected the whole model rather than ignoring the line. A typo in a parameter name is not a warning you can ignore.
Building a Modelfile from a local GGUF
The reason this article can promise measurements instead of opinions: FROM accepts a local GGUF, so you can test a prompt format against a 19 MB file instead of a 4 GB download.
FROM ./stories15M-q4_0.gguf
PARAMETER num_ctx 512
PARAMETER temperature 0
SYSTEM You are a terse assistant that answers in one word.
TEMPLATE """{{ if .System }}<|system|>
{{ .System }}
{{ end }}{{ if .Prompt }}<|user|>
{{ .Prompt }}
{{ end }}<|assistant|>
"""
$ ollama create story-sys -f Modelfile
success
$ ollama list
NAME ID SIZE MODIFIED
story-sys:latest c2f0acb84dad 19 MB Less than a second ago
Two things you can already see in that listing. The size is the base model’s size: SYSTEM, PARAMETER and TEMPLATE add no weights. And the two models I built with different templates but the same FROM shared one weights layer — story-sys and story-nosys reported the same layer hash, because the prompt format lives in the manifest, not in the tensor blob. That is also why the same model can be re-created with a different template without re-downloading anything.
Honest take: what a Modelfile does not fix
- It does not make a small model smart. The test model produced fluent-looking English and no useful content. A template is a formatting contract, not a capability.
- It does not change the weights. Every variant in this test ran the same 24.41M parameters. If your problem is quality, the answer is a different model, not a different template — and for verifying that a model file is intact before you spend VRAM on it, the blob digest check is the tool for that job (/blog/ollama-blob-digest-verify-model-integrity-2026/).
- It does not replace the server’s own defaults.
PARAMETERvalues are per-model defaults; a request can still override them through theoptionsfield of the API. - It does not survive a careless round trip.
ollama show --modelfilerewritesFROMas a blob path. That is valid on the machine that created the model and useless as a portable blueprint — if you want to share the model, share theFROMname and the rest of the file, not the generated one.
Start from ollama show --modelfile <model> to see what you actually have, check whether the template mentions {{ .System }}, and only then start editing. If the template has no system slot, that is your bug, and it is one line to fix.
Sources
- Modelfile reference: format, all eight instructions,
FROMshapes, parameter table, template variables — Ollama documentation - Chat API: request fields,
options, and theprompt_eval_count/prompt_eval_cached_countresponse fields — Ollama documentation - Generate API: request and response fields — Ollama documentation
- Ollama API reference in the upstream repository (
docs/api.md) — github.com/ollama/ollama - Ollama release v0.40.16, published November 9, 2026 — GitHub releases API
- ggml-org/models:
tinyllamas/stories15M-q4_0.gguf(19,077,344 bytes) — Hugging Face
Last updated November 18, 2026. The behaviour above was checked against the Ollama documentation and the upstream API reference on November 18, 2026, and reproduced locally with Ollama 0.40.16 on CPU using a 19 MB test model from the llama.cpp test corpus. The token counts are real measurements of what Ollama sent to the model; the model’s own output text is meaningless and no quality claim is made from it. No paid API, no hosted service, no hardware benchmark.
Was this article helpful?
Thanks for the feedback — it helps improve future articles.
Need hands-on help?
I offer 1-on-1 technical consulting for local AI setup, GPU selection, and AI coding tool configuration — same topics covered on this site.
Book a session — $49 / hour →Get the numbers before you buy
New GPU and mini-PC benchmarks, VRAM thresholds, and price checks — sent when there's something worth acting on, not on a schedule. No spam, unsubscribe anytime.