New Tool Radar

AI Concepts

How to Teach an Ollama Model a Format With MESSAGE Examples

Add MESSAGE lines to a Modelfile so the model sees example question-and-answer pairs before it ever answers you.

Schematic diagram with four steps: pick a base model, add user and assistant MESSAGE pairs in the same format, create the model, then test it with a fresh question.

A system prompt tells a model how to behave, but a few examples show it. The Modelfile MESSAGE instruction lets you bake example exchanges into the model itself, so every chat starts with the model having seen how you want answers shaped.

Add example messages and rebuild the model

Write the Modelfile with a FROM base, then add MESSAGE lines in order: a user message with an example question, then an assistant message with the answer in the format you want. The reference says you can use multiple MESSAGE iterations to build up a conversation that guides the model to answer in a similar way. Valid roles are system, user and assistant. Create the model and test it with a fresh question in the same shape as your examples.

FROM llama3.2
MESSAGE user Summarise this in one sentence: The cat sat on the mat.
MESSAGE assistant The cat sat on the mat.
# then:
ollama create one-sentence-summariser -f Modelfile

Keep the examples short and consistent: three pairs that all follow the same format teach more than ten pairs that vary. If the model ignores the format, the examples are probably too long or contradictory — shorten them and rebuild. Rebuilding after changing only MESSAGE lines is fast, under a few seconds in the docs’ experience.

Try it: four checks

Check What you should see If you do not see it
Messages valid The Modelfile uses system, user or assistant roles Fix any other role name
Create succeeds ollama create finishes without an error Check the FROM base model is pulled
Format followed A fresh question gets an answer in the example format Shorten and align the examples
Consistent Several test questions all follow the format Add one more example pair if not

Expected result. We checked the Ollama Modelfile reference, which says MESSAGE specifies message history, lists system, user and assistant as valid roles, and describes building a conversation from multiple MESSAGE lines. We did not build a model on this machine.

Limits

This guide covers MESSAGE examples only. Examples do not retrain the model — a model that cannot do the task will not learn it from examples. We did not test any model ourselves.

Sources

See all