Own It

Persistent Instructions With Ollama Modelfiles

Give your local AI a consistent personality and behavior across new chats - not stored memory of past conversations, but instructions that never need repeating.

12 minute read
Last tested: August 2026 · Ollama 0.33.2

The problem this solves

By default, every new chat starts from zero.

If you always want responses kept short, or always want the model to answer as if explaining to a beginner, or always want it to avoid a certain tone, you'd normally have to type those instructions again at the start of every conversation.

A Modelfile fixes this by baking a system prompt directly into a custom model. Once it's built, that behavior is just how the model works, every time, without you repeating anything.

Writing a Modelfile

Create a plain text file named Modelfile (no extension) with contents like this:

FROM llama3.2

SYSTEM """
You are a direct, concise assistant. Keep answers short unless
asked to go deeper. Avoid corporate speak and hedging language.
"""

The FROM line points at a base model you already have installed. The SYSTEM block is the instruction that now applies automatically, every time this custom model is used.

Don't start from a blank page. Every model already ships with its own default Modelfile. See what you're actually starting from before writing one by hand:
ollama show llama3.2 --modelfile
Copy that output as your starting point and edit the SYSTEM block, rather than guessing at the format from scratch.

Here's what that actually looks like, run against a real installed model:

Terminal showing the output of ollama show qwen2.5-coder --modelfile, listing the model's default template, system prompt, and parameters

The default Modelfile for an installed model - this is the exact starting point you'd copy and edit, not something you'd write from a blank page.

Tuning behavior beyond the prompt

A Modelfile can do more than set a system prompt. A PARAMETER line adjusts how the model actually generates text - the two worth knowing as a beginner:

FROM llama3.2

SYSTEM """
You are a direct, concise assistant.
"""

PARAMETER temperature 0.3
PARAMETER num_ctx 8192

temperature controls randomness - lower values (like 0.3) give more focused, repeatable answers, useful for a "factual assistant" model. Higher values (like 0.9) give more varied, creative output. num_ctx sets the model's context window - how much conversation history it keeps in memory at once - raising it lets longer conversations stay coherent, at the cost of using more RAM.

A second example - a "quick answers" model:
FROM llama3.2

SYSTEM """
Answer in one or two sentences unless explicitly asked for more detail.
No preamble, no "great question" - just the answer.
"""

PARAMETER temperature 0.2
Build it the same way: ollama create quick-answers -f ./Modelfile. Now you have both a default assistant and a terse one, and you switch between them the same way you'd switch between any two models.

Building your custom model

From the same folder as your Modelfile, run:

ollama create my-assistant -f ./Modelfile

That's it - my-assistant now shows up alongside your other models, in Open WebUI's dropdown and in the terminal, and it carries your system prompt automatically.

ollama run my-assistant
This is genuinely useful, not just a novelty. A few well-considered Modelfiles - one for quick answers, one for detailed explanations, one for a specific recurring task - save real repeated typing over time.

What actually goes wrong

The build command fails immediately

Check that the base model named in the FROM line is actually pulled already:

ollama list

If it's not there, pull it first, then run ollama create again.

The custom model doesn't seem to follow the system prompt

Smaller models are less reliable at consistently following system instructions than larger ones - this is a real model capability limit, not a setup mistake. If a 3B model is ignoring the prompt, the same Modelfile against a 7-8B base model usually behaves noticeably better.

You want to update the prompt later

Edit the Modelfile and run the same ollama create command again with the same name - it overwrites the existing custom model cleanly.

The build fails with a quoting or formatting error

The triple-quote """ block needs to open and close on its own - don't nest additional double quotes inside a SYSTEM block without escaping them. If your prompt needs to reference actual quotation marks, use single quotes inside the block instead of doubles to avoid confusing the parser.

Common questions

Is this the same as RAG?
No. A system prompt shapes how the model behaves and responds in general. RAG pulls in specific document content. They solve different problems and work well together.
Does a custom Modelfile use more storage?
Barely any. It is a small text file plus a reference to the base model you already have - not a full copy of the model itself.

Go deeper

This guide covers one solid path. Here's where to go if you want something different.

Changelog

  • 2026-08-31: Renamed from "Giving Your AI Memory" to "Persistent Instructions With Ollama Modelfiles" - this is a system prompt baked into a custom model, not stored memory of past conversations.
  • 2026-08-31: Tightened the page title to match the more precise headline.
Keep exploring See everything else worth knowing, whenever you actually want it.
Explore more guides →

Written from hands-on security operations experience. More about this site →