Building custom Ollama models with a Modelfile

A Modelfile packages an approved base model with fixed settings, a system prompt and a chat template so every team member gets the same behavior. This page explains the instructions, the configuration choices and how to version and roll out the files.

On this page

Why teams build custom Ollama models with a Modelfile

When several teams pull the same base model and each applies its own system prompt, sampling settings and context length, the server ends up hosting many near-identical models that answer differently. A Modelfile is a plain-text build recipe that names a FROM base, sets PARAMETER defaults, a SYSTEM prompt, a TEMPLATE, a LICENSE and a REQUIRES minimum Ollama version, and produces a named model on the server that every client can call by one name. The only mandatory instruction is FROM. The optional MESSAGE instruction seeds example conversation turns, and CAPABILITY declares what the model can do, so clients and tooling can see those traits without guessing.

A plain pull is enough when one team uses a model as shipped and accepts its defaults. A Modelfile earns its place when the organization needs a fixed behavior that people cannot quietly change: an approved system prompt, a pinned num_ctx for a documented context window, a temperature and top_k that match a review, or a LICENSE block that travels with the weights. Defaults such as temperature at 0.8, top_k at 40, top_p at 0.9 and num_predict at -1 (unlimited) are what the model uses when nothing else is set, so a Modelfile is the place to decide whether those values should stand. Confirm the parameter names and accepted values against the Ollama Modelfile reference for the release you run.

Before building, decide who owns each setting and who approves changes to the recipe. Check that the base model's own license allows the derivative you intend to publish internally, and record which Ollama version the team tested with so REQUIRES is set to a version you have actually run. Treat the Modelfile as a reviewable artifact: a change to the system prompt or a sampling value is a behavior change, and it should go through the same review and versioning as other configuration. Illustrative example: a claims team might publish claims-summarizer with a fixed system prompt and a lower temperature, while the general-purpose base model stays available for everyone else.

Modelfile instructions and parameters, and when each fits

This table lists each Modelfile instruction and parameter, what it controls and whether a team should fix it in the Modelfile or leave it to the calling application. Read it as a starting point for deciding which settings define the approved model and which remain per-request choices. The main takeaway is that pinning settings makes behavior repeatable across users, but num_ctx also sets memory use, so it needs sizing against the hardware before it is fixed.

Instruction or parameterWhat it controlsWhen to pin itWhen to leave it to the caller
FROMThe base model or local weights the custom model is built on. Required in every Modelfile.Always. Name the exact approved base so every build traces to one source.Not applicable. Callers choose a custom model name, not its base.
PARAMETER num_ctxContext window size in tokens. Ollama allocates memory for it when the model loads.Pin when the team has sized VRAM or RAM for one context length and needs predictable memory use.Leave to callers only if every server has spare memory and the team has checked usage with ollama ps.
PARAMETER temperatureRandomness of sampling. The documented default is 0.8.Pin for extraction, classification or review tasks where repeatable output matters.Leave for creative or conversational tools where users or apps vary the style per request.
PARAMETER top_k and top_pLimits on candidate tokens during sampling. Documented defaults are 40 and 0.9.Pin alongside temperature so the team can describe and test one sampling profile.Leave when the application already sends its own sampling values and the team does not need to override them.
PARAMETER seed and num_predictSeed fixes the random sequence for repeatable runs. num_predict caps output length, with a documented default of -1 for unlimited generation.Pin num_predict when a runaway answer would break a downstream system. Pin seed only for tests and regression checks.Leave seed unset in production so varied output is not frozen. Leave num_predict to callers that need long outputs.
PARAMETER stopSequences that end generation early, such as a delimiter or end-of-turn marker.Pin when the template or downstream parser depends on a specific stop sequence.Leave when callers use different output formats and send their own stop values.
TEMPLATEThe prompt format that wraps messages for the model. A wrong template degrades answers even when the weights are correct.Pin for every custom build, and confirm it matches the base model's documented format.Rarely left to callers. Changing it per request usually breaks the model's expected turn structure.
SYSTEMDefault system instructions applied to every conversation with the model.Pin for role, scope, tone and refusal rules the team has approved and reviewed.Leave to callers when each application supplies its own system prompt. Confirm that callers cannot silently remove pinned rules.
LICENSEEmbeds the license text for the model weights in the Modelfile build.Pin for every custom model so the terms travel with the artifact in the internal catalog.Not applicable. Callers do not set licensing terms.
MESSAGEExample conversation turns added to the model's starting context.Pin when a few worked examples reliably shape the output format for one approved use case.Leave when examples grow large, since each example uses context tokens on every request.
REQUIRESThe minimum Ollama version needed to build or run the model.Pin for every build so an older server does not load it with unexpected behavior.Not applicable. Set by the team that owns the server version.
CAPABILITYDeclares capabilities such as tool use or vision that the model is expected to support.Pin only after testing each capability on the approved base, and record the result in the build notes.Not applicable for callers. Confirm the declared capabilities against the base model's documentation before publishing.

How to create and test a team model step by step

This sequence takes an approved base model from license check to a team-scoped Ollama model that is stored on the server and answers requests with the settings the team fixed in the Modelfile. Each step ends with a check so the platform owner knows the model is ready for others to use.

  1. Confirm the base model and its license

    The platform owner and the team lead confirm which base model the organization has approved, which version is being pulled, and what its license permits, including commercial use, redistribution and any attribution or usage terms. Record the model name, tag and license text in the team's configuration repository. The step is done when someone outside the build can point to the approved source and the license file that governs it.

  2. Write the Modelfile with FROM and parameters

    Create a plain text file named Modelfile in a version-controlled directory. Start with a FROM line that names the approved base model, then add PARAMETER lines for the settings the team wants fixed, such as num_ctx, temperature, top_k, top_p, seed, stop and num_predict. Note that temperature defaults to 0.8, top_k to 40, top_p to 0.9 and num_predict to -1, which means unlimited generation, so any value you do not set keeps those defaults. The step is done when the file contains one FROM line and every parameter has a deliberate value.

  3. Add SYSTEM, TEMPLATE and LICENSE instructions

    Add a SYSTEM instruction that sets the role and rules for the team, and a TEMPLATE only if the base model's prompt format needs changing for your use. Add a LICENSE instruction that carries the license text confirmed in step one, so the packaged model states its terms. Keep the system prompt free of secrets or personal data, because anyone who can run the model can read it. The step is done when a reviewer has read the complete file and agrees the instructions match the approved use.

  4. Create the model with a team-scoped name

    On the Ollama host, run ollama create with a name that includes the team or purpose, for example a team prefix and a version tag, and point it at the Modelfile. Ollama reads the base model, applies the instructions and writes a new model to the local store. The step is done when the command completes without errors and the new name is listed by ollama list on that host. Use a version tag in the name so later changes do not overwrite the model that other users depend on.

  5. Test with ollama run and the local API

    Start an interactive session with ollama run using the new model name and check the answers against the expected behavior. Then send a request to the REST API on port 11434 with the model name, for example with curl or the Python SDK, and confirm the response matches what the terminal showed. The local API does not require authentication, so keep these tests on the host. It only accepts connections from other machines if OLLAMA_HOST has been changed, and that change should be planned with the access controls in place. The step is done when both paths return consistent answers and the parameters behave as written.

  6. Check the stored location and server listing

    Confirm where Ollama placed the model. By default models live in ~/.ollama/models on macOS, /usr/share/ollama/.ollama/models on Linux and the .ollama\models folder on Windows, unless OLLAMA_MODELS points elsewhere. Check that the storage path is on the disk your team has planned for model storage and backups. Then confirm the model appears in the server listing that other users will see. The step is done when the location matches the storage plan and the model name appears in the listing on the server.

  7. Store the Modelfile with the team's configuration

    Commit the Modelfile, the license file and a short record of the exact base model tag and ollama create command to the team's version control system, alongside other platform configuration. Tag the commit with the model version so the build can be repeated and the change history shows who altered a parameter or instruction. The step is done when a second team member can rebuild the same model from the repository on a test host and get the same listing and behavior.

How a Modelfile fits into the server and the model store

A Modelfile is a text source file, and ollama create turns it into a named model on your server. The build starts from the base model named in the FROM instruction, then applies the PARAMETER, TEMPLATE, SYSTEM and LICENSE settings on top. The result is stored in the model directory alongside the weights it depends on, so the server can later load it under the name you gave it. Ollama stores models in ~/.ollama/models on macOS, /usr/share/ollama/.ollama/models on Linux and the .ollama\models folder under the user's profile on Windows. Set OLLAMA_MODELS to move that store to another directory, such as a volume with capacity planned for your model catalog. Confirm exactly which layers a build writes and which it reuses in the Ollama Modelfile reference before you plan disk space or cleanup routines.

Because the Modelfile is a separate source file from the weights, it can be reviewed, diffed and stored in version control like other configuration. The weights may be large binary files, while the Modelfile is short enough that a reviewer can read every default a team will receive. Keep the Modelfile, the base model reference and the version of Ollama used for the build together in one repository, so a change to a parameter or system prompt has an author, a reason and a rollback point. Record the Ollama version in the same place, since the REQUIRES instruction exists to state the minimum version a model needs. Ask your platform team to confirm how builds behave across server upgrades in your environment before you promise stability to users.

Trade-offs when pinning settings in a shared Modelfile

A Modelfile lets a team fix the base model, parameters and system prompt once and hand out one name to every caller. Each setting you pin is a decision about who controls output quality, how many models sit in memory and how much memory each request can use. The four decisions below are the ones that most often need revisiting after a team starts using the model.

Pin sampling values or let callers override

Setting temperature, top_k and top_p in the Modelfile gives every caller the same sampling behavior, which helps consistency for review and extraction tasks. Ollama's defaults are a temperature of 0.8, a top_k of 40 and a top_p of 0.9, so a team that never sets these inherits values chosen for general use. Check whether your client applications send their own options per request, because a request-level value will replace the pinned one. Decide which values are contractual and document which ones callers may change.

Modelfile reference

One broad system prompt or per-application prompts

A single SYSTEM instruction in a shared model is easy to govern, but it tends to grow into a long compromise that serves no application well. Per-application prompts keep each instruction short and testable, at the cost of more model names to track and more Modelfiles to version. Test the broad prompt against the riskiest use case first, since a rule that is harmless for chat may distort a structured extraction task. Write down which team owns each prompt and who approves changes.

One model per use case or many variants

Each Modelfile variant is a separate named model, and Ollama loads models into memory on demand. The number of models that can stay loaded at once is limited by OLLAMA_MAX_LOADED_MODELS, which defaults to 3 times the number of GPUs, or 3 on CPU. If five variants of the same base model are called in rotation, the server may unload and reload them repeatedly, which adds latency. Count your variants against the loaded-model limit and the memory each one needs before you publish them.

Ollama FAQ

Fixing num_predict and num_ctx

num_ctx sets the context window and num_predict caps generated output, and both are pinned in a Modelfile as fixed values. A larger context window uses more memory for every loaded instance, so a value that suits a long document review can exhaust VRAM for a short chat tool sharing the same server. The default for num_predict is -1, which means unlimited generation, so a runaway response can occupy a slot for a long time. Agree on both values with the teams that send requests, and test them against your largest expected input.

How to version Modelfiles alongside other configuration

Should Modelfiles be stored in Git with the rest of the server configuration?

Yes, store every Modelfile in the same Git repository as the server configuration, such as the environment file or service unit that sets OLLAMA_HOST and OLLAMA_MODELS. A Modelfile only makes sense together with the base model it names in FROM, the parameters it sets and the environment the server runs with, so reviewing them as one change keeps the team from drifting apart. Commit each Modelfile with a clear message, require a review before merge, and keep the file name tied to the model name so anyone can trace what is running on a host back to a commit.

How should custom Ollama model names be tagged with versions?

Give each build a model name that includes a version, for example a team name, a purpose and a version number, and avoid reusing the latest tag for internal models. Rebuilding a model under the same name changes what every client receives without any code change, so a new version should get a new tag and clients should move to it deliberately. Record the tag, the Git commit and the base model reference in the same change so an incident review can answer which exact definition served a request.

How does REQUIRES pin a minimum Ollama version in a Modelfile?

The REQUIRES instruction in a Modelfile sets the minimum Ollama version that can build or run the model, so a host on an older release fails clearly instead of producing unexpected behavior. Set it to the lowest release your team has tested, not to the newest release you have seen. Because Ollama publishes frequent releases, a pinned minimum protects hosts that lag behind, but it does not stop an upgrade from changing behavior, so the server release should also be pinned in configuration and tested before it is rolled out.

Why record the exact Ollama release used for each model build?

Record the exact Ollama release on every host, because the runtime changes often and a model that works on one release may behave differently on another. Ollama publishes frequent releases, such as v0.40.5 released on 14 October 2026, and a pre-release such as v0.40.6 published on 16 October 2026. Treat pre-releases as test-only unless your own testing approves them. Store the release number in the same repository, update it through a reviewed change, and check the Ollama GitHub releases page before each upgrade to read what changed.

How should a Modelfile move from a test host to production?

Promote Modelfiles through the same path as application code: build on a test host with the same Ollama release and base model file that production will use, run a fixed set of prompts and checks, review the diff, then deploy the same commit to production. Avoid rebuilding by hand on production, because a rebuild can pull different base weights or a different runtime. Keep a short written test list covering output format, refusal behavior, context length and speed, and record the result next to the commit so the approval is auditable.

How do you roll back when a base model or template changes?

Roll back by redeploying the previous Git commit and its recorded Ollama release, not by editing the live model in place. Keep the previous model tag available on the host until the new version has passed its checks, and make sure the base model file it depends on is still present in the model store. If a base model or template changes upstream, treat it as a new version: pin the exact base reference you tested, so an update cannot silently alter the template your applications depend on. Confirm with your own tests that the rolled-back model reproduces the earlier behavior.

Who should own Modelfile versioning inside the organization?

Assign ownership to the platform or AI operations team that runs the Ollama servers, with a named reviewer from the application team that depends on each model. The platform team controls the server release and environment settings, and the application team approves changes to system prompts and default parameters that affect its output. Decide who can approve a promotion to production, who can start a rollback, and where those decisions are logged. Your internal policies and any compliance program you follow will decide how much evidence that trail must hold.

Security and licensing checks before publishing a team model

A team model inherits the license, provenance and exposure of everything it is built from. The checks below cover what you are allowed to publish, where the weights came from, how the server is reached and what sits inside the model definition and storage.

Review the license of base and derived weights

Read the license attached to the base model weights named in FROM, then confirm that your derived model, fine-tune or quantized copy is still allowed under those terms. Model licenses differ from the MIT license that covers the Ollama runtime itself, and they can restrict commercial use, redistribution or the use of outputs. Keep the license text with the Modelfile and record who approved it. Ask legal to confirm whether the model's LICENSE instruction needs to carry the original terms unchanged.

Modelfile reference

Verify provenance of the FROM source

Establish where the base weights came from before anything references them. Record the publisher, the download location, the file hashes and the date retrieved, and confirm that the artifact you packaged is the one you reviewed. A FROM line that points at a mutable tag or an unverified local file makes the published model hard to reproduce or defend in an audit. Keep approved sources in an internal catalog so that every team model traces back to a known origin.

Put access control in front of the API

The local Ollama API on port 11434 has no authentication of its own, so anyone who can reach the server can call every model it hosts. Bind the server to a private address with OLLAMA_HOST only when needed, and place an authenticating reverse proxy or gateway in front of it. Confirm which users, service accounts and networks can reach the published team model, and test that unauthenticated requests are refused from outside the approved network.

Ollama FAQ

Keep secrets out of SYSTEM prompts

The SYSTEM instruction is stored in the model definition and can be read back by anyone with access to the model, so treat it as visible configuration. Do not place API keys, passwords, internal hostnames, customer data or detailed security rules in it. Keep credentials in your secrets manager and pass them to the calling application at runtime. Review each system prompt as a document that may be shared, copied or exposed through a proxy log.

Control and back up the model store

Published models live in the model directory, which is ~/.ollama/models on macOS, /usr/share/ollama/.ollama/models on Linux and the .ollama\models folder on Windows unless OLLAMA_MODELS moves it. Restrict write access to the service account and to the people who publish models, and keep read access to the server only. Back up the store together with the Modelfiles and license records, and test that a restored model runs and matches its recorded configuration.

Confirm who can publish and approve changes

Define who may build, tag and replace a team model, and who signs off the license, provenance and system prompt review before a new version goes live. Write this approval path down with the Modelfile in version control. Ask your team to confirm whether a second reviewer is required for changes to SYSTEM, TEMPLATE or the base model, since those change behavior for every user of the model.

How a Modelfile moves from source to a served team model

The Modelfile starts as a reviewed text file in Git, not as a model on someone's laptop. A staging host runs ollama create to build the named model, and the team tests it through the local API on that host. Only after those tests pass is the same Modelfile promoted to the production server, where it sits behind an authentication proxy because the Ollama API itself has no authentication. Clients then call the named model rather than a base model, so the settings stay fixed. Check that staging and production run the same Ollama version and the same model weights.

The same Modelfile moves from reviewed source through staging into a proxied production server.

Questions teams ask before building custom Ollama models

Does building a custom Ollama model cost money?

Building the model itself does not carry a license fee. Ollama is licensed under the MIT license, and the pricing page states that running models on your own hardware is always unlimited. The costs come from three places: the staff time to write the Modelfile, build and test the model, and maintain it, the hardware that runs it, and any paid Ollama cloud plan if your team chooses to use cloud models. Paid cloud plans are optional and are listed on the pricing page. For a local, self-hosted build, the main line item is people's time. Ask whoever estimates the work to break it into base model review, Modelfile authoring, test set creation, evaluation runs and ongoing version updates, since each one recurs differently.

How long does a first team model take to produce?

The duration depends mostly on how much testing you require before the model is approved for team use. A Modelfile that sets a base model, a system prompt and a few parameters can be written quickly, but the work that takes time is confirming the behavior: running a fixed test set, comparing outputs against expectations, and fixing the template or parameters where results drift. A team that only needs a personal convenience model will move faster than one that needs documented evaluation, sign-off from a prompt owner and a repeatable build. No duration figure has been established for this work, so ask any provider or internal lead to commit to a timeline only after the test scope and approval steps are written down.

What does the team need to provide before the work starts?

Four inputs decide whether the build goes smoothly:

  • Approved base model: a named model and version your governance process has cleared, with its license reviewed for your use.
  • Prompt owners: the people who decide what the system prompt and template should say and who accept changes.
  • A test set: representative prompts, expected behaviors and failure cases that every version must pass before release.
  • A Git workflow: a repository where Modelfiles, test sets and parameter notes are versioned, reviewed and tagged alongside the rest of your configuration.

Without the test set and owners, the build tends to stall at approval rather than at the Modelfile itself.

Can our own engineers build a custom Ollama model alone?

Yes, a capable engineering team can write a Modelfile and create a custom model using the Modelfile reference and the Ollama documentation. The Modelfile instructions are compact: FROM is required, and PARAMETER, TEMPLATE, SYSTEM, LICENSE, MESSAGE and REQUIRES cover most team needs. The harder parts are outside the file format. Your team needs to decide which parameter defaults are safe, verify that the template matches the base model, keep the model under version control, and keep the server's security settings in order. If no one on the team has run a model evaluation before, plan time for that learning. A partner is most useful when you want the evaluation and governance evidence prepared in a form reviewers can follow.

Which Modelfile settings do engineers most often need to check?

Engineers should review the settings that change how the model behaves on every request. The documented parameters include num_ctx, temperature (default 0.8), top_k (default 40), top_p (default 0.9), seed, stop and num_predict (default -1 for unlimited generation). Set the defaults deliberately, because callers can override some of them per request, and a num_predict of -1 can produce very long outputs if nothing else limits them. Check that the TEMPLATE matches the chat format of the base model, and that the SYSTEM text does not contain secrets or internal details you would not want echoed back. Record the chosen values in version control so a reviewer can see what changed between releases.

Does the Modelfile itself create a security or compliance risk?

The Modelfile is a configuration file, so its main risks are what it contains and where the resulting model is used. A system prompt or template can hold internal instructions, and a LICENSE instruction should carry the terms of the base model accurately. Local Ollama does not see your prompts or data, but the API at localhost:11434 has no authentication by default, so the server that serves your custom model must be protected separately. Ollama binds to 127.0.0.1 by default, and exposing it through a proxy such as Nginx needs an authentication layer in front. Ask your security team to review the Modelfile, the base model source and the server access path together, not as isolated items.

When does a DeployOpen scope make sense for a custom model?

A DeployOpen scope makes sense when you want the model build, the test evidence and the operating setup handled as one agreed piece of work inside your infrastructure. DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms in your own cloud accounts, data centers or air-gapped networks, and most engagements are fixed-scope with deliverables and timelines agreed in writing before work starts. A scope might cover the base model review, Modelfile packaging, a test set, server hardening and handover documentation. DeployOpen does not issue audit reports or certifications, so any compliance evidence it prepares would go to your independent auditors. A quote follows from the written scope, and DeployOpen does not publish a price list.

How should teams version Modelfiles alongside other configuration?

Store each Modelfile in the same Git repository as the rest of the platform configuration, such as server settings, test sets and deployment manifests. Give every release a tag or version label, and record the base model name and version it was built from so a rebuild can be reproduced. Changes to SYSTEM, TEMPLATE or parameter defaults should go through the same review as code changes, with the prompt owner approving the wording. Keep the test results next to the commit so reviewers can see which behavior changed. Ollama ships frequent releases, so also record the Ollama version your build was tested on, since a new release can change behavior and the REQUIRES instruction can state a minimum version your team has tested against.

Official Ollama references for Modelfiles

Start with the Ollama Modelfile reference before you write your first team Modelfile. It is the authoritative list of instructions, including the required FROM line and the optional PARAMETER, TEMPLATE, SYSTEM, LICENSE, MESSAGE, REQUIRES and CAPABILITY instructions. Read it against the version of Ollama your servers actually run, because the REQUIRES instruction only helps if your platform team sets the minimum version to match what is deployed. Confirm the parameter names and defaults on that page, since the values your team sets in PARAMETER lines should be checked there rather than copied from older examples.

The Ollama FAQ answers the operational questions that surround a custom model: where model files are stored, how the server binds to the network, and which environment variables control concurrency and cloud features. A custom model built from a Modelfile lives in the same store as the base model, so the storage location and the OLLAMA_MODELS setting matter for who can read and back up the packaged model. Use the FAQ to confirm those settings on your own servers before you document the model as approved for a team.

The Ollama GitHub repository is where to check open issues and recent changes to Modelfile handling, especially before a version upgrade that could change how a packaged model loads. Because Ollama ships frequent releases, treat the repository and its release notes as the place to confirm whether an instruction behaves as your Modelfile expects on the version you are moving to. Record the Ollama version used for each approved Modelfile alongside the file itself so that a rebuild can be tested against that same release.

How DeployOpen scopes and delivers custom Ollama models

DeployOpen plans, builds, tests, documents and hands over custom Ollama Modelfiles inside your own infrastructure. Each engagement starts with a written, fixed scope that names the approved base model, the parameters, the license terms and the versioning approach before any build work begins.

How we scope

  • Inventory the approved base model, its license terms and which team members may publish new variants
  • Agree the parameter set, system prompt, template and REQUIRES minimum version in writing before the build
  • Define which Modelfile versions go to which Ollama servers, and who approves each change
  • Confirm the hosting target, including where OLLAMA_MODELS points and whether cloud features stay off

How we build

  • Write the Modelfile with FROM, PARAMETER, TEMPLATE, SYSTEM and LICENSE instructions for the agreed use case
  • Test default parameter values such as num_ctx, temperature, top_k, top_p and num_predict against agreed test prompts
  • Keep Modelfiles in version control next to the server configuration and deployment scripts
  • Check that the built model loads, responds through the REST API on port 11434 and behaves as the scope describes

How we hand over

  • Deliver the Modelfile, build commands and a record of the base model version and parameter values used
  • Document how to roll back to an earlier Modelfile version and how to rebuild the model on a new server
  • Walk your platform and compliance teams through the license, data handling and change control evidence
  • Provide a handover session so your team can create and review the next Modelfile version without us

How we support

  • Offer ongoing support, upgrades and retesting of custom models as a retainer when your team wants it
  • Retest custom models when the base model, the Ollama version or the server configuration changes
  • Review the written scope when requirements change, and quote any added work before it starts
  • Confirm support terms, response expectations and the retainer scope in writing before work begins

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.