Few-Shot With MESSAGE
Use Modelfile MESSAGE directives to preload few-shot examples and lock in a strict output format.
TL;DR
MESSAGElines preload example turns into the model.- Pair
MESSAGE userwithMESSAGE assistantto show format. - Prime strict output without training a
LoRAadapter.
The MESSAGE Directive
MESSAGE userAdd an example user turn to the history.
MESSAGE user "Convert 5 to roman"MESSAGE assistantAdd the ideal assistant reply to copy.
MESSAGE assistant "V"MESSAGE systemSeed a system role message when needed.
MESSAGE system "Reply in roman numerals."Order MattersList pairs in the order the model should read.
# user, then assistant, repeatedPrime A Format
Show The PatternGive one clean example of the exact output.
MESSAGE user "3"
MESSAGE assistant "III"Repeat For StrengthTwo or three pairs reinforce the format.
MESSAGE user "9"
MESSAGE assistant "IX"Strict SyntaxExamples teach the exact symbols to emit.
MESSAGE assistant "VII"Few-Shot vs LoRA
No TrainingMESSAGE primes behavior with zero training runs.
# No dataset, no GPU training neededADAPTERA LoRA adapter changes weights via a trained file.
ADAPTER ./lora-adapter.ggufWhen To TrainUse LoRA for deep style or knowledge shifts.
# LoRA for big, permanent behavior changeBuild And Test
ollama createBake the examples into a named model.
ollama create roman-bot -f ModelfileRun ItThe model follows the primed format.
ollama run roman-bot "7"Adjust ExamplesEdit the pairs and rebuild to refine.
ollama create roman-bot -f ModelfileTips
- Add two or three
MESSAGEexample pairs to lock in a strict output format, which is faster than fine-tuning for many tasks. - Keep few-shot examples short and consistent, since the model copies their style, spacing, and structure in its own replies.
Warnings
- Too many
MESSAGEexamples eat the context window and slow each request; a few strong examples usually beat a long list. - Baked-in
MESSAGEexamples apply to every request; send runtime messages instead when the examples should change per call.
In Practice
Use MESSAGE example pairs in a Modelfile so a model always answers in one fixed format, with no training.
- The heredoc writes a Modelfile with a system rule and example pairs.
- Each user and assistant pair shows the exact format to copy.
ollama createbakes the examples into every future request.- A new number comes back in the same roman-numeral format.
# Write a Modelfile with few-shot pairs
cat > Modelfile <<'EOF'
FROM llama3.2
SYSTEM """Reply with roman numerals only."""
MESSAGE user "3"
MESSAGE assistant "III"
MESSAGE user "9"
MESSAGE assistant "IX"
EOF
# Build and test the primed model
ollama create roman-bot -f Modelfile
ollama run roman-bot "7"FAQ
MESSAGE preloads a fixed conversation turn into the model, using MESSAGE user and MESSAGE assistant lines. Ollama treats these as prior history, so the model sees your examples before it answers a new prompt.
Few-shot examples steer the model at prompt time with no training, so they are instant to change. Fine-tuning or a LoRA adapter actually updates weights, which is more powerful but needs a dataset and compute.
Usually two to four strong, consistent pairs. More examples reinforce a format but consume the context window and slow each request, so stop once the model reliably copies the pattern.
Use MESSAGE examples for formatting and simple behavior shaping. Reach for a LoRA adapter when you need a deep, permanent change in style or knowledge that a few examples cannot capture.