AIForum.

What Is an Ollama Modelfile? Custom System Prompts, Parameters, and Templates

On this page

THE SHORT ANSWER

An Ollama Modelfile is the plain-text blueprint that tells Ollama how to build and run a customized model. It combines a base model with a system message, runtime parameters, a prompt template, and metadata. This guide explains each instruction, walks through a minimal build, and separates the three parts people most often confuse: FROM, SYSTEM, and TEMPLATE.
Quick facts

An Ollama Modelfile is a plain-text blueprint that tells Ollama how to build and run a customized model. It pairs a base model with the settings that shape its behavior: a system message, runtime parameters, a prompt template, and metadata such as license and the minimum Ollama version required. If you want a local model that consistently answers in a particular voice, uses a larger context window, or follows a chat format that a raw base model does not handle by default, the Modelfile is where that configuration lives.

This guide is for anyone who has run a model with ollama run and now wants to change how it behaves without retraining anything. It covers the file’s structure, a minimal working example, and the three pieces people most often confuse: FROM, SYSTEM, and TEMPLATE.

What a Modelfile actually controls

A Modelfile uses a simple, line-based format. A comment begins with #; every other line is an instruction followed by its arguments. Ollama’s Modelfile reference documents eight instructions.

InstructionWhat it does
FROM (required)Defines the base model to use. It can point at an existing Ollama model, a Safetensors model, or a GGUF model.
PARAMETERSets the parameters for how Ollama will run the model.
TEMPLATEThe full prompt template to be sent to the model.
SYSTEMSpecifies the system message that will be set in the template.
LICENSESpecifies the legal license.
MESSAGESpecifies message history.
REQUIRESSpecifies the minimum version of Ollama required by the model.
CAPABILITYDeclares an additional model capability.

Only FROM is mandatory. Everything else is optional, which is why a single-line Modelfile is technically valid — it simply reproduces the base model under a new name.

A minimal Modelfile you can build and run

The official example creates a persona on top of llama3.2:

FROM llama3.2

# sets the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 1

# sets the context window size to 4096, this controls how many tokens
# the LLM can use as context to generate the next token
PARAMETER num_ctx 4096

# sets a custom system message to specify the behavior of the chat assistant
SYSTEM You are Mario from super mario bros, acting as an assistant.

To use it:

  1. Save the text as a file named Modelfile.
  2. Build the model: ollama create mario -f ./Modelfile
  3. Run it: ollama run mario

The expected result is that ollama create reports a successful build and the interactive session behaves according to the system message. To confirm what Ollama actually stored, run ollama show --modelfile mario. If you change the file later, re-run ollama create with the same name to rebuild.

SYSTEM and TEMPLATE are not the same thing

SYSTEM sets a single string: the system message. The documentation describes it as the system message “that will be set in the template.” That phrasing matters. SYSTEM does not inject anything on its own; it populates the .System variable that a template can reference.

TEMPLATE, by contrast, is the complete prompt text — including special tokens, role headers, and turn delimiters — that Ollama sends to the model on each request. It is written in Go’s built-in templating engine, so it supports variables, conditionals, and loops.

The practical consequence: if you write a custom TEMPLATE and forget to include {{ .System }}, your system prompt is silently dropped. Nothing errors out. The model simply behaves as though the instruction was never written, which is one of the most common reasons a carefully crafted persona appears to “not work.”

How templates work in practice

Ollama’s template documentation describes three parts: a layout, variables, and functions. A minimal chat loop looks like this:

{{- range .Messages }}
{{ .Role }}: {{ .Content }}
{{- end }}

The variables available inside a template are:

  • System (string) — the system prompt
  • Prompt (string) — the user prompt
  • Response (string) — the assistant response
  • Suffix (string) — text inserted after the assistant’s response
  • Messages (list) — the message history, with .Role and .Content per item

Models imported into Ollama default to a template of {{ .Prompt }}. That sends user input verbatim, which is appropriate for text or code completion models but lacks the essential markers that chat and instruction models expect. The documentation is explicit that omitting a template in those cases puts the responsibility of correctly templating input onto the user.

Here is the documented Llama 3 template, which shows how the system message and each conversation turn are wrapped in the tokens that model family expects:

FROM llama3.2
TEMPLATE """{{- if .System }}<|start_header_id|>system<|end_header_id|> {{ .System }}<|eot_id|> {{- end }} {{- range .Messages }}<|start_header_id|>{{ .Role }}<|end_header_id|> {{ .Content }}<|eot_id|> {{- end }}<|start_header_id|>assistant<|end_header_id|> """

Two cautions apply. First, special tokens such as <|start_header_id|> are model-specific: they come from the model’s own chat format, and borrowing another family’s markers will degrade output even though nothing crashes. Second, templates are exact — a missing space or newline can shift results. Adapt the documented template for your model family rather than composing one from scratch.

Parameters: temperature, context window, and the rest

PARAMETER lines control how Ollama runs the model rather than what the model knows. The reference example uses two:

PARAMETER temperature 1
PARAMETER num_ctx 4096

temperature governs sampling: the documentation describes higher values as more creative and lower values as more coherent. num_ctx sets the context window, which the docs describe as controlling how many tokens the LLM can use as context to generate the next token.

Context size carries a hardware cost. A larger num_ctx increases the KV cache, which occupies memory alongside the model weights, so raising it on a memory-constrained machine can slow generation or cause failures. Treat the context window as a memory tradeoff rather than a free upgrade. The Modelfile reference documents the full set of valid parameters and values; check it rather than assuming a parameter name borrowed from another runtime will work.

Inspecting and iterating on a Modelfile

Any model already in your local library can be inspected. Running:

ollama show --modelfile llama3.2

prints a generated Modelfile. The output begins with a comment explaining how to reuse it: replace the FROM line with the model you inspected, and you have a working starting point for your own build. The practical loop is inspect, copy, edit, ollama create, test, and repeat.

Because a Modelfile is small and plain text, it is also the natural unit for sharing a customized model — the same reason the documentation calls it “the blueprint to create and share customized models.” Sharing a Modelfile shares configuration and behavior, not weights, so recipients still need the base model available locally.

Limitations worth knowing before you build

  • A Modelfile does not change model weights. It configures a base model. The underlying capability is whatever FROM points at, so a task beyond the base model will not be fixed by a system prompt.
  • LICENSE records a license; it does not grant rights. The terms that actually apply are those of the base model and any weights you import. Open weights, open source, and commercial-use permission are not interchangeable, so read the applicable license before redistributing a build.
  • REQUIRES matters for sharing. If your Modelfile depends on a newer Ollama feature, declaring the minimum version prevents confusing failures on older installs.
  • MESSAGE seeds conversation history. It is useful for few-shot examples, but those turns consume context on every request.
  • Build errors usually point at FROM. A model name that is not present locally, or a Safetensors or GGUF path Ollama cannot read, will stop the build before any other instruction is evaluated. Confirm the base model runs with ollama run before layering instructions on top of it.

A sensible order of operations

Start with the smallest change that solves your problem: add a SYSTEM line to an existing chat model, build it with ollama create, and verify the result with ollama show --modelfile. Add a PARAMETER only when you can describe the specific behavior you want to change, and change one at a time so you can attribute the difference. Reach for a custom TEMPLATE last, and only by adapting the documented template for your model family — it is the part most likely to break output quietly.

If you try a configuration and get unexpected results, sharing the exact Modelfile, the base model tag, and the output you observed is usually enough for the community to spot the problem. Post your file and what you expected to see.

FAQ

Does creating a Modelfile retrain or modify the model?

No. A Modelfile is configuration layered on top of a base model. It sets the system message, runtime parameters, prompt template, and metadata; the underlying weights are unchanged, and capability is still bounded by whatever FROM points at.

Why does my system prompt seem to have no effect?

The most likely cause is a custom TEMPLATE that does not include {{ .System }}. SYSTEM only populates that variable, so a template that omits it silently discards the system message without producing an error.

Can I edit the Modelfile of a model I already downloaded?

You can inspect it with ollama show --modelfile , copy the generated output, adjust it, and rebuild under a new name with ollama create. The generated file includes a comment explaining that you should replace the FROM line to base a new Modelfile on it.

Do I need a custom TEMPLATE for a chat model?

Models imported into Ollama default to {{ .Prompt }}, which sends input verbatim. That suits text or code completion, but chat and instruction models generally need their expected role markers, so using the documented template for that model family is the safer choice.

Does a larger num_ctx always improve results?

Not necessarily. A larger context window increases the KV cache, which consumes memory alongside the weights and can slow generation or cause failures on constrained hardware. Increase it only when your task genuinely needs more context.

References

  1. https://docs.ollama.com/modelfile
  2. https://docs.ollama.com/template

Related terms

Base model
The model named in the FROM line. A Modelfile configures this model rather than replacing it, so the base model's capabilities set the ceiling.
SYSTEM
A Modelfile instruction that sets the system message string. It only reaches the model if the active template references the .System variable.
TEMPLATE
The full prompt template sent to the model, written in Go template syntax. It controls role markers, turn delimiters, and how system and user content are assembled.
num_ctx
A parameter setting the context window size in tokens. Larger values increase the KV cache and therefore memory use during generation.
GGUF
A model file format that a Modelfile's FROM line can point at, alongside existing Ollama models and Safetensors sources.

Leave a Reply

Your email address will not be published. Required fields are marked *