A Modelfile is a small text file that builds a custom model from a base model plus a system prompt and parameter settings. It is how you give a local model a fixed role without changing the base model.
What you need
- Ollama installed and a base model pulled, for example llama3.2
- A text editor for the Modelfile
- A terminal in the folder that will hold the Modelfile
Step 1: Write the Modelfile
Create a file named Modelfile with these lines: FROM llama3.2 on the first line, then a SYSTEM line with the role, for example SYSTEM You are a concise maths tutor. Answer in short steps. Add PARAMETER lines such as PARAMETER temperature 0.3 if you want steadier answers.
Step 2: Create the model
Run ollama create my-teacher -f Modelfile in that folder. Ollama reads the file, builds the model, and reports success. The new model name my-teacher is yours to choose.
Step 3: Run and test it
Run ollama run my-teacher and ask a question in its domain. The system prompt applies to every message in the chat, and ollama show my-teacher lists the parameters the Modelfile set.
Worked example: a maths tutor model
The table below is a synthetic example. The Modelfile lines follow the documented format; the model name is illustrative.
| Part | Content | Expected result |
|---|---|---|
| Base | FROM llama3.2 | Base model used |
| Role | SYSTEM You are a concise maths tutor. | Short-step answers |
| Create | ollama create my-teacher -f Modelfile | success |
Expected result (UNTESTED). ollama create reports success, ollama run my-teacher answers in the tutor style, and ollama show lists the system prompt. This check was not run live; the Modelfile format comes from the cited docs.
Limits
- The base model must already be pulled before ollama create runs.
- A Modelfile SYSTEM message is fixed at creation; editing it needs a new ollama create.
- Parameter names must match the documented Modelfile format.
- The custom model shares the base model weights, so it costs little extra disk space.
