Implementation:Ollama Ollama Modelfile Format Spec
| Knowledge Sources | |
|---|---|
| Domains | Configuration, DSL |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Pattern specification for the Modelfile configuration language used to define custom models in Ollama.
Description
This is a Pattern Doc — it documents a user-authored format rather than a library API. The Modelfile is a text file containing directives that configure a custom model. The format is parsed by the parser package.
The Modelfile struct in the parser package holds the parsed commands. The Command struct represents each directive with Name and Args fields.
Usage
Users author Modelfiles when creating custom models via ollama create. The file is read and parsed by ParseFile before being processed by the creation pipeline.
Code Reference
Source Location
- Repository: ollama
- File: parser/parser.go
- Lines: L30-55 (Modelfile struct), L326-369 (Command struct)
Interface Specification
# Modelfile Format Specification
# Required: base model
FROM <model_name_or_gguf_path>
# Optional: system prompt (multiline with triple quotes)
SYSTEM """
You are a helpful assistant.
"""
# Optional: inference parameters
PARAMETER temperature 0.7
PARAMETER top_k 40
PARAMETER top_p 0.9
PARAMETER num_ctx 4096
PARAMETER stop "<|end|>"
# Optional: chat template override (Go text/template)
TEMPLATE """
{{- range .Messages }}
<|{{ .Role }}|>
{{ .Content }}
{{- end }}
"""
# Optional: LoRA adapter
ADAPTER /path/to/adapter.gguf
# Optional: license
LICENSE """
MIT License...
"""
# Optional: preset messages
MESSAGE user "Hello"
MESSAGE assistant "Hi! How can I help?"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| FROM | string | Yes | Base model name or path to GGUF file |
| SYSTEM | string | No | System prompt text |
| PARAMETER | key-value | No | Inference parameter (temperature, top_k, etc.) |
| TEMPLATE | string | No | Go text/template for prompt formatting |
| ADAPTER | string | No | Path to LoRA adapter file |
| LICENSE | string | No | Model license text |
| MESSAGE | role + content | No | Preset conversation message |
Outputs
| Name | Type | Description |
|---|---|---|
| Modelfile | Parsed struct | Modelfile struct with Commands slice |
| CreateRequest | api.CreateRequest | Translated API request for model creation |
Usage Examples
Basic Custom Model
# Create a Modelfile
cat > Modelfile << 'EOF'
FROM llama3
SYSTEM "You are Mario from Super Mario Bros."
PARAMETER temperature 0.8
EOF
# Create the model
ollama create mario -f Modelfile
# Run it
ollama run mario
Model with LoRA Adapter
cat > Modelfile << 'EOF'
FROM llama3
ADAPTER ./my-lora-adapter
PARAMETER num_ctx 8192
EOF
ollama create custom-llama -f Modelfile