Learn › Local AI: Run Models on Your Own Machine › Customizing Models with Modelfiles

Customizing Models with Modelfiles

Beginner 🕐 12 min Lesson 6 of 13
What you'll learn
  • Understand what a Modelfile is and what the FROM, SYSTEM, and PARAMETER instructions do
  • Set temperature and context window parameters to suit different task types
  • Create a named custom model from a Modelfile with ollama create

What Is a Modelfile?

A Modelfile is a plain text configuration file that tells Ollama how to build a custom model variant. Think of it as a Dockerfile for AI — you specify a base model, set its personality and constraints via a system prompt, tune its generation parameters, and give the result a name. From then on, ollama run my-custom-model launches your configured version directly.

Modelfiles solve a common frustration: re-typing the same system instructions every time you start a chat. With a Modelfile, you bake those instructions into the model once and never type them again.

Modelfile Syntax

Every Modelfile starts with a FROM instruction naming the base model. All other instructions are optional.

FROM llama3.3 SYSTEM """ You are a senior software engineer who writes clean, well-tested Python code. When asked to write code, always include type hints and a brief docstring. When reviewing code, point out both problems and what is working well. Never write code you would be embarrassed to put in a production pull request. """ PARAMETER temperature 0.2 PARAMETER num_ctx 8192

The Key Instructions

FROM — the base model to build on. Use any model name that Ollama knows: llama3.3, qwen3, phi4-mini, or a specific tag like llama3.3:70b.

SYSTEM — the system prompt. This text is injected at the start of every conversation before the user’s first message. Use triple quotes for multi-line prompts. This is where you define the model’s role, constraints, tone, and any persistent context it should always have.

PARAMETER temperature — controls how predictable or creative the output is. Values range from 0.0 (deterministic, picks the most likely token every time) to 1.0 (more varied and creative). For factual tasks, coding, and structured output use 0.0–0.3. For creative writing use 0.7–1.0. The default for most models is 0.8.

PARAMETER num_ctx — the context window size in tokens. This determines how much conversation history the model can hold at once. The default is often 2048. Setting it to 4096 or 8192 lets the model remember more of a long conversation, at the cost of more VRAM. Do not set this higher than your VRAM comfortably supports.

Building and Running Your Custom Model

Save your Modelfile to disk (filename can be anything — Modelfile is the convention), then run:

ollama create coding-assistant -f Modelfile

Ollama builds the custom model in seconds and registers it locally. Run it with:

ollama run coding-assistant

List it alongside your other models with ollama list. Remove it with ollama rm coding-assistant.

Example: A Focused Writing Coach

Here is a second example tuned for writing feedback rather than code:

FROM mistral-small3 SYSTEM """ You are a direct, constructive writing editor. Your job is to help the user write more clearly and concisely. When given a piece of writing: 1. Identify the single most important improvement it needs 2. Rewrite one specific sentence or paragraph to demonstrate the improvement 3. Explain in one sentence why the rewrite is better Do not comment on everything. Focus on the highest-leverage change. """ PARAMETER temperature 0.4 PARAMETER num_ctx 4096

Create it with: ollama create writing-coach -f Modelfile

When Modelfiles Are Most Useful

Modelfiles are most valuable when you have a task you return to repeatedly — a coding assistant, a document reviewer, a customer email responder, a role-specific chatbot for a team. For one-off tasks, just use ollama run llama3.3 and include the system prompt inline. Modelfiles pay off when you want the same configured assistant every time you open a terminal.

Key takeaways
  • A Modelfile bakes a system prompt and generation parameters into a named model so you never re-type setup instructions
  • temperature 0.0-0.3 for precise/factual tasks; 0.7-1.0 for creative tasks; num_ctx controls conversation memory at the cost of VRAM
  • ollama create <name> -f Modelfile builds the variant in seconds; it appears in ollama list and runs with ollama run <name>