Local LLMs

Ollama Modelfile: a Custom Model With a System Prompt

3 min read

A Modelfile is Ollama’s recipe: a base model plus a standing instruction and settings, built into a new model you call by name. Stop pasting the same preamble into every script — bake it once. Prerequisite: Ollama installed (Windows or macOS and Linux). Prefer clicking to typing? Generate one in the Modelfile builder.

1. Write the Modelfile

In any folder, create a file called Modelfile:

FROM llama3.2

SYSTEM """
You are a blunt code reviewer. Lead with bugs and risks.
Be terse. Use bullet points. No praise.
"""

PARAMETER temperature 0.4
PARAMETER num_ctx 8192

FROM names the base model and tag, SYSTEM """…""" holds the multi-line standing instruction, and each PARAMETER sets one runtime option. The instructions are not case sensitive and may appear in any order, though FROM first reads best.

2. Pick parameters that matter

temperature controls variation — 0.2–0.4 for review and extraction, 0.8 upwards for drafting. num_ctx sets the context window, and raising it costs memory: check what your machine can hold with RAM and VRAM requirements before asking for 32k.

Two more directives are worth knowing. TEMPLATE overrides how prompts are formatted for the base model, which you almost never need to touch, and MESSAGE seeds an example exchange into every conversation — a cheap way to demonstrate a format instead of describing it. ADAPTER attaches a fine-tuned LoRA on top of the base.

3. Build it

ollama create reviewer -f ./Modelfile

Turns the file into a model named reviewer. It layers on the base rather than copying it, so a variant costs almost nothing on disk.

4. Run it

ollama run reviewer "review this: def add(a,b): return a-b"

Starts with your system prompt already applied. The name works anywhere a normal model does, including the HTTP API.

Verify it worked

ollama show --modelfile reviewer

Prints the recipe Ollama actually stored — your SYSTEM text and every PARAMETER should be there. If it fails: model not found means the FROM tag was never pulled, so run ollama pull llama3.2 first; and unquoted multi-line text without """ silently truncates at the first newline. Full directive list: the Modelfile reference.

Open the full interactive version (with copy buttons) ↗

← All guides