How to create a custom Modelfile for Ollama
Ollama installed, a base model already pulled (e.g., `ollama list` shows a model), and a text editor available.
What this does
A Modelfile is a configuration text file that defines model parameters, system prompts, template overrides, and runtime behavior. This guide creates a custom Modelfile, imports it into Ollama, and runs the customized model.
Steps
Create a new directory and Modelfile. The Modelfile uses a declarative syntax to override default behavior.
mkdir -p ~/ollama-models/myassistant cd ~/ollama-models/myassistant nano ModelfileExpected output: An empty text editor buffer opens for the new file.
Write the Modelfile content. This example sets a system prompt, adjusts temperature, and specifies the base model.
cat << 'EOF' > Modelfile FROM llama3.2:1b PARAMETER temperature 0.7 PARAMETER top_p 0.9 SYSTEM """ You are a helpful assistant. Answer concisely. """ EOFExpected output: File
Modelfilecreated with the content above. Verify withcat Modelfile.Create the custom model using
ollama create. This imports the Modelfile and builds a named model variant.ollama create myassistant -f ModelfileExpected output:
successmessage confirming the model was created and registered.Run the custom model to verify behavior. The system prompt and parameters defined in the Modelfile govern the inference session.
ollama run myassistantExpected output: Interactive prompt appears. Responses reflect the defined system prompt and temperature setting.
Verification
ollama list | grep myassistant
# Expected: myassistant <id> <size> <date>
Common failures
ollama createfails with parse error — Modelfile syntax error. Check for missing colons, incorrect keywords, or unquoted multi-line strings.- Model runs with wrong parameters — Cached default parameters may persist. Delete and recreate with
ollama rm myassistant && ollama create myassistant -f Modelfile. - FROM model not found — The base model has not been pulled. Run
ollama pull llama3.2:1bfirst. - Parameter value out of range — Some parameters have specific bounds (e.g., temperature must be between 0 and 2). Consult Ollama documentation for valid ranges.
- System prompt not applied — Template overrides may conflict with system prompt. Simplify the Modelfile to isolate the issue.