Ollama Modelfile Guide: System Prompts, Templates and Parameters
Write Ollama Modelfiles that work: FROM, SYSTEM, PARAMETER, TEMPLATE and MESSAGE, context size, sampler settings, adapters and copying an existing model.
Ollama models are defined by a Modelfile. Learning its handful of instructions gives you full control over any model you run.
The instructions
| Instruction | What it does |
|---|---|
| FROM | The base: a library model name or a path to a GGUF |
| SYSTEM | The default system prompt |
| PARAMETER | Settings such as num_ctx, temperature, top_p, stop |
| TEMPLATE | The chat template that wraps messages |
| MESSAGE | Example conversation turns |
| ADAPTER | A LoRA adapter to apply |
| LICENSE | The licence text |
A working example
FROM ./mistral-small-24b-abliterated.Q4_K_M.gguf
PARAMETER num_ctx 16384
PARAMETER temperature 0.8
PARAMETER repeat_penalty 1.05
SYSTEM """You are a frank creative writing partner. Stay in the user's chosen style. Ask before changing the plot."""
Then run ollama create writer -f Modelfile and ollama run writer.
Copy before you edit
ollama show --modelfile llama3.1 prints the full Modelfile, including the template. Save it, change what you need and create a new model.
Templates
If replies ramble, repeat role labels or never stop, the template or stop tokens are wrong. Take the template from the model card or copy it from a library model of the same family.
Context and memory
Larger num_ctx costs memory. Check the trade-off with the context length calculator.
System prompts
Draft a clear one with the uncensored system prompt builder. Getting models into Ollama is covered in uncensored models in Ollama.
Common questions
Where do I put a Modelfile?
Anywhere. Save it as a text file and run ollama create name -f path/to/Modelfile.
How do I change the context length?
Add PARAMETER num_ctx with the number of tokens you want, such as 16384, then recreate the model.
Can I edit a library model's system prompt?
Yes. Run ollama show --modelfile on it, save the output, change the SYSTEM line and create a new model from it.
Related reading
Uncensored Models in Ollama: Find, Import and Configure
GuideLM Studio Guide: Download, Run and Serve Local Models
Guidellama.cpp Guide: Run, Serve and Quantise Models Yourself
ComparisonFree Ollama Alternative: Uncensored AI Model Hub vs Ollama (2026)
Free toolUncensored System Prompt Builder
Browse more: all guides · comparisons · glossary · free tools