Modelfile Blueprints

Write a Modelfile to set a base model, bake in a system prompt, and lock default parameters.

TL;DR

  1. FROM sets the base model every Modelfile builds on.
  2. SYSTEM bakes a persistent persona into the model.
  3. Set defaults like PARAMETER temperature 0 for repeatable output.

Modelfile Basics

    FROM

    Set the base model or weights to build on.

    FROM llama3.2
    SYSTEM

    Bake a persistent system prompt into the model.

    SYSTEM """You are a terse SQL tutor."""
    PARAMETER

    Set a default runtime option for every run.

    PARAMETER temperature 0.2
    Comments

    Lines starting with a hash are ignored.

    # This is a comment in a Modelfile

Common Parameters

    temperature

    Control randomness; 0 is deterministic, higher is creative.

    PARAMETER temperature 0
    num_ctx

    Set the context window size for the model.

    PARAMETER num_ctx 8192
    stop

    Add a stop sequence that ends generation.

    PARAMETER stop "<|im_end|>"
    seed

    Fix the random seed for reproducible output.

    PARAMETER seed 42

Build And Run

    ollama create

    Build a named model from the Modelfile.

    ollama create sql-tutor -f Modelfile
    Run It

    Start the custom model like any other.

    ollama run sql-tutor
    Rebuild After Edits

    Re-run create so edits take effect.

    ollama create sql-tutor -f Modelfile
    Inspect It

    Show the resolved Modelfile of a model.

    ollama show sql-tutor --modelfile

Beyond The Basics

    ADAPTER

    Apply a LoRA adapter on top of the base.

    ADAPTER ./lora-adapter.gguf
    LICENSE

    Embed a license string in the model.

    LICENSE """MIT License"""
    TEMPLATE

    Override the prompt template, covered next chapter.

    TEMPLATE """{{ .Prompt }}"""

Tips

  1. Put a clear SYSTEM prompt in the Modelfile so every run starts with the same role, without re-typing instructions each time.
  2. Set PARAMETER temperature 0 when you need deterministic output, such as extraction or classification tasks that must be repeatable.

Warnings

  1. ollama create rebuilds the model each time; re-run it after editing the Modelfile, or your changes will not take effect.
  2. A very low temperature can make a model repetitive or terse; test values between 0 and 0.7 for your task.

In Practice

FAQ