Yeda AI Tips · #047

Lock In a Local Model's Behavior With a Modelfile

Ask a general-purpose local model to "only answer homework questions by guiding, never giving the answer directly," and it might comply — for one message. Start a new chat, and the instruction is gone. If you want a rule that sticks every time, you don't put it in the chat. You put it in a Modelfile.

The problem with chat-only instructions

A system prompt typed into a chat window lives only in that session. Close the window, switch devices, or let someone else use the same model, and the rule disappears. For anything you want to reuse — a support bot that won't wander off-topic, a homework helper that won't just hand out answers, an assistant with a fixed persona — retyping instructions every time isn't a workflow, it's a chore waiting to be skipped.

Why a Modelfile fixes it

Ollama lets you define a new model on top of an existing one using a small text file called a Modelfile. It specifies a base model plus a system prompt (and optionally other parameters), and once you build it, the result is a real, separately-named model on your machine — not a chat setting, a model. Anyone who runs that name gets the rules baked in, every time, with zero setup.

How to do it

  1. Create a file named Modelfile (no extension) anywhere on disk.
  2. Add two lines to start:
    FROM llama2
    SYSTEM "You are a homework helper. Guide the student toward the answer with hints and questions. Never give the final answer directly."
    FROM picks the base model already available via Ollama. SYSTEM is the instruction applied to every conversation with this new model, automatically.
  3. Build the model: ollama create homework-helper -f Modelfile. This registers homework-helper as its own model name, backed by llama2 plus your system prompt.
  4. Run it like any other model: ollama run homework-helper. No need to paste instructions again — the rule is compiled in.
  5. Clean up when you're done. ollama rm homework-helper removes the custom model without touching the base model it was built from.

Where this fits

Pitfalls

Power tricks

Resources

Building an AI feature? Yeda AI designs, audits, and ships production LLM systems.

Talk to us · Read the blog