Modelfile Blueprints
Write a Modelfile to set a base model, bake in a system prompt, and lock default parameters.
TL;DR
FROMsets the base model every Modelfile builds on.SYSTEMbakes a persistent persona into the model.- Set defaults like
PARAMETER temperature 0for repeatable output.
Modelfile Basics
FROMSet the base model or weights to build on.
FROM llama3.2SYSTEMBake a persistent system prompt into the model.
SYSTEM """You are a terse SQL tutor."""PARAMETERSet a default runtime option for every run.
PARAMETER temperature 0.2CommentsLines starting with a hash are ignored.
# This is a comment in a ModelfileCommon Parameters
temperatureControl randomness; 0 is deterministic, higher is creative.
PARAMETER temperature 0num_ctxSet the context window size for the model.
PARAMETER num_ctx 8192stopAdd a stop sequence that ends generation.
PARAMETER stop "<|im_end|>"seedFix the random seed for reproducible output.
PARAMETER seed 42Build And Run
ollama createBuild a named model from the Modelfile.
ollama create sql-tutor -f ModelfileRun ItStart the custom model like any other.
ollama run sql-tutorRebuild After EditsRe-run create so edits take effect.
ollama create sql-tutor -f ModelfileInspect ItShow the resolved Modelfile of a model.
ollama show sql-tutor --modelfileBeyond The Basics
ADAPTERApply a LoRA adapter on top of the base.
ADAPTER ./lora-adapter.ggufLICENSEEmbed a license string in the model.
LICENSE """MIT License"""TEMPLATEOverride the prompt template, covered next chapter.
TEMPLATE """{{ .Prompt }}"""Tips
- Put a clear
SYSTEMprompt in the Modelfile so every run starts with the same role, without re-typing instructions each time. - Set
PARAMETER temperature 0when you need deterministic output, such as extraction or classification tasks that must be repeatable.
Warnings
ollama createrebuilds the model each time; re-run it after editing theModelfile, or your changes will not take effect.- A very low
temperaturecan make a model repetitive or terse; test values between0and0.7for your task.
In Practice
Write a Modelfile with a system prompt and zero temperature, build it, then run repeatable output.
- The heredoc writes a Modelfile with a system role and fixed seed.
temperature 0plus a fixedseedmake output repeatable.ollama createbakes all of it into a named model.- Running the model needs no extra flags; the behavior is built in.
# Write the Modelfile
cat > Modelfile <<'EOF'
FROM llama3.2
SYSTEM """Extract dates as YYYY-MM-DD only."""
PARAMETER temperature 0
PARAMETER seed 42
EOF
# Build the custom model
ollama create date-bot -f Modelfile
# Run it; behavior is baked in
ollama run date-bot "Meeting next Tuesday"FAQ
A Modelfile is a plain-text recipe for a custom model. It sets a base model with FROM, an optional system prompt with SYSTEM, and default options with PARAMETER. You build it into a model with ollama create.
Add a SYSTEM instruction to the Modelfile, then run ollama create. Every run of that model then starts with the same role, so you do not have to repeat the instructions in each prompt.
Set PARAMETER temperature 0 and a fixed PARAMETER seed. Temperature zero removes randomness, and a fixed seed makes repeated runs return the same result for the same prompt.
Yes. Editing the Modelfile does not change an existing model. Run ollama create again so the new settings are baked into the model.