NeMo Guardrails with local models on Ollama

Connect NeMo Guardrails to models served by Ollama using the built-in ollama engine, then decide which self-check rails a small local model can carry and when CPU-only hardware is no longer enough.

On this page

How NeMo Guardrails connects to Ollama local models

A team that wants guardrails in front of a model it runs on its own hardware can use the built-in ollama engine in NeMo Guardrails rather than adding a separate integration layer. The engine's default base URL is which is the OpenAI-compatible endpoint that Ollama serves on port 11434. The engine supports streaming and tool calls, and reasoning models where the engine supports them. Ollama's local API at localhost:11434 requires no authentication, so the config.yml` model entry typically needs only the engine name and model name, with the base URL changed only when Ollama listens somewhere else. Confirm the exact keys against the NeMo Guardrails supported LLMs documentation for the release you install, since model entry syntax changes between versions.

The boundary to define first is where each component runs. By default Ollama binds to 127.0.0.1 on port 11434, so the guardrails process must run on the same host or be able to reach that address. If the guardrails server runs in a container, localhost inside the container is not the Ollama host, and the base URL must point to a host address the container can reach. If you change OLLAMA_HOST to expose Ollama on a network interface, the unauthenticated API becomes reachable by anything on that network, so put it behind a proxy with access control, such as the Nginx approach the Ollama FAQ describes, or keep it on a private segment. Do not expose the local API to the internet.

Your team owns the sizing decisions. The NeMo Guardrails library can run on CPU with a minimum of 1 CPU and 4 GB RAM, but the model that answers the application, and any small model used for self-check rails, consumes its own memory and compute through Ollama. Ollama's concurrency settings, including OLLAMA_NUM_PARALLEL and OLLAMA_MAX_LOADED_MODELS, decide how many requests one model handles at a time, and each guardrail call adds model calls on top of the application call. Measure latency and memory with your chosen model under realistic prompts before you commit to CPU-only hardware, and confirm with Ollama's documentation how these variables behave on your platform.

What you need before configuring the ollama engine

Before you write a config.yml that points at Ollama, the Python runtime, the host size, the network bind and the model storage location all need to be settled. Each card below is a check that prevents a common failure once guardrails start calling a local model.

Python runtime version

NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13. Install the library into a virtual environment built on one of those versions and confirm it with python --version before installing nemoguardrails. Older interpreters often install without an obvious error and then fail when the library imports, so check the version on the build host and on any container image you plan to use.

PyPI package

CPU and memory floor

The library runs on CPU with a minimum of 1 CPU and 4 GB RAM. That floor covers the guardrails runtime only. The model Ollama serves needs its own memory, so a model that fits in RAM alongside the runtime is a separate sizing question. Measure both on the target machine under realistic load rather than treating the library minimum as the whole budget.

Default bind address

Ollama listens on 127.0.0.1 port 11434 by default, so only processes on the same host can reach it. A guardrails server running in a container or on another host will get connection errors unless you set OLLAMA_HOST deliberately. If you expose the port, the Ollama FAQ describes placing a proxy such as Nginx in front, and the API itself has no built-in authentication for local use, so that proxy must enforce access.

Ollama FAQ

Model storage locations

Ollama keeps pulled models in ~/.ollama/models on macOS, /usr/share/ollama/.ollama/models on Linux and the .ollama\models folder under the user profile on Windows. Model files can run to many gigabytes, so confirm the disk that holds these paths has room for every model you plan to test. Set OLLAMA_MODELS to move the store to a larger or encrypted volume before the first pull.

Ollama FAQ

External models and GPUs

The guardrails runtime can run on CPU, but any model it calls may need accelerators deployed separately. A small local model for self-check rails may be workable on the same CPU host, while a larger model or a safety classifier sized for GPUs belongs on separate hardware. Decide which rail calls which model before you size the host, and confirm the GPU requirement of each model with its vendor.

Installation guide

Ollama version compatibility

Confirm the Ollama version you run supports the API behavior your configuration depends on, such as streaming and tool calls. Ollama ships frequent releases, including pre-releases, so pin a tested version rather than tracking the latest tag. Check the release notes on the Ollama releases page against your configuration before any upgrade, and retest after each change.

Ollama releases

How to configure the ollama engine in config.yml

This sequence takes a team from a clean Python environment to a running NeMo Guardrails configuration that sends main and self-check requests to a model served by a local Ollama instance. Each step ends with a check you can run before moving on.

  1. Install NeMo Guardrails in a supported Python environment

    The engineer creates a virtual environment using Python 3.11, 3.12 or 3.13, which are the versions NeMo Guardrails 0.25.0 requires, and installs the nemoguardrails package from PyPI. Installing into a fresh environment keeps the pinned version separate from other projects on the same machine. The step is complete when running the nemoguardrails command-line help prints its usage text without an import error and the installed version reports 0.25.0 or the release you have chosen to adopt.

  2. Install Ollama and pull a small chat model

    The engineer installs Ollama on the host that will run the model, then pulls a small chat model that fits the memory available on that host. Ollama stores downloaded models in its default model directory unless the OLLAMA_MODELS variable points elsewhere, so confirm that location has enough free disk space before the pull starts. The step is complete when ollama list shows the model name and the model responds to a single prompt typed at the terminal.

  3. Confirm the Ollama endpoint is reachable

    By default Ollama binds to 127.0.0.1 on port 11434 and its local API does not require authentication. The engineer sends a direct request to the OpenAI-compatible chat completions path under with the model name from the previous step. If the host runs Ollama on another interface, this is the point to confirm the OLLAMA_HOST value and that the calling process can reach it. The step is complete when curl returns a JSON chat completion containing a message from the model.

  4. Create the config folder and the models block

    The engineer creates a configuration folder containing a config.yml file. In the models block, the main model entry sets type to main, engine to ollama, and model to the exact tag shown by ollama list. The base URL is unless the endpoint was changed in the previous step. The step is complete when the file parses as valid YAML and the nemoguardrails server or the Python loader starts without reporting an unknown engine or a missing model.

  5. Select a model for self-check rails

    The engineer adds a second models entry with type set to self_check_input or self_check_output, or assigns the same local model to the rails that use it, and checks the rail prompts in the configuration. A small local model can handle the yes or no classification prompts used by self-check rails, but output quality from a small model should be tested against your own policy examples rather than assumed. Ask the team that owns the policy to supply the examples. The step is complete when the configuration loads and the rails list in the startup log shows each self-check rail bound to a model.

  6. Run a test request through the Python API

    The engineer writes a short script that loads the configuration folder, creates the rails object, and sends a benign user message through generate. The script should also send a message that a self-check input rail is expected to block, so the team sees both paths. The step is complete when the benign message returns a normal model response and the blocked message returns the configured refusal text instead of a model answer.

  7. Run a test request against the guardrails server

    The engineer starts the guardrails server against the same configuration folder and sends an HTTP request to its chat endpoint with curl, using the configuration identifier if more than one is loaded. This confirms the server reads the same models block as the Python API and returns the guarded response over HTTP. The step is complete when the server returns the same allowed and blocked behavior as the Python test, and the server log shows the Ollama request was made.

Streaming and tool calls through Ollama

The NeMo Guardrails supported LLMs documentation lists streaming as available with the built-in ollama engine, so a chat application can show tokens as the local model generates them instead of waiting for a full completion. Streaming changes where guardrails fit in the request path. The team should decide early whether a rail must see the complete answer before any token reaches the user, because that decision sets both latency and exposure.

  • Confirm the engine and base URL: Set the engine to ollama in config.yml and confirm the base URL is ` unless your Ollama server is bound to another address.
  • Test through the client path users take: Run the streaming test through the same client code, Python API or HTTP server, that production will use, since the two paths can behave differently.
  • Measure time to first token: Compare the same prompts with rails on and off so you know what output checking adds before the first visible token.
  • Check interrupted streams: Confirm what the client receives when a rail stops generation partway through, and whether partial text has already been displayed.

Check each of these in your own build, on the NeMo Guardrails version you deploy, because streaming behavior depends on configuration and release.

Choosing a small local model for self-check rails

A small model running on Ollama can handle self-check input and output moderation, but every check it performs adds latency and depends on how well the model follows policy text. The cards below cover the decisions your team has to make and the tests that should back each one before a configuration goes into use.

Latency added to every request

Self-check rails call the model before and after the main response, so each guarded request can pay the model's inference time more than once. On CPU-only hardware, that cost is often the first thing users notice. Measure end-to-end latency with the rails enabled, under the concurrency you expect, and compare it with the same application without guardrails. Ask whether the extra calls can run in parallel with the main model before you accept the result.

Accuracy on your policy checks

A self-check prompt is only as reliable as the model's ability to answer a yes or no question about your policy. Smaller models can miss subtle violations or flag harmless text, and the errors may differ from one policy to another. Build a labeled set of allowed and blocked examples from your own traffic and record false positives and false negatives for each rail. Treat any model that fails your set as unfit for that rail, even if it works well on general chat.

Context length for long inputs

Self-check rails send the user message, the model's draft response and the policy prompt in one request, so long inputs can crowd out the instructions. Check the context window of the model you pull, and confirm how Ollama is configured to handle context for your deployment. Test with the longest inputs your application accepts, because a check that truncates silently can pass content it should have blocked. Decide the maximum input size at the application layer and enforce it before the rails run.

Testing each rail against the model

Each rail can behave differently on the same model, so a passing test on one input rail says little about an output rail that uses a different prompt. Run every configured rail against the exact model name, quantization and Ollama version you plan to deploy, and keep those values in your test record. Repeat the tests after any model pull, Ollama upgrade or prompt change. Adding a new rail should always trigger its own test run.

Who owns model selection

The choice of model, its size and its accuracy for each policy are decisions your team makes and answers for. DeployOpen can help set up the evaluation, but it does not supply benchmark results for specific models in this guide, and model quality can change with each release. Confirm the owner of model approval, the review date and the criteria for replacing a model before it reaches production. Record who signed off on the evaluation results.

How a request flows from the app through rails to Ollama

The request starts in the application, which calls NeMo Guardrails instead of Ollama directly. Input rails run first, and any self-check call goes to a model endpoint, which can be the same Ollama server or a separate one. If the input passes, the main model on Ollama at localhost:11434 produces a draft, output rails check it, and only then does the response return to the app. Check which hops leave the host, since the Ollama API has no authentication on its local endpoint.

Request path from the application through guardrails to the Ollama endpoint.

Where CPU-only hardware stops being enough

A CPU-only host stops being enough when latency and queueing, not model quality, become the limiting factor. The first sign is response time that grows as concurrent users are added, even when a single request on an idle machine feels acceptable. Ollama controls concurrency with three settings: OLLAMA_NUM_PARALLEL (default 1 parallel request per model), OLLAMA_MAX_LOADED_MODELS (default 3 on CPU, or 3 times the number of GPUs) and OLLAMA_MAX_QUEUE (default 512 queued requests). With the parallel default, requests for the same model wait in line behind one another, so guardrail traffic and the main application traffic compete for the same slot.

The second sign is multiplication of model calls. A self-check input or output rail sends its own prompt to the model before or after the main completion, so one user request can become two or more inference calls, and a dialog or fact-checking rail can add more. Each of those calls consumes the same CPU time as the answer itself. Count the model calls per request in your configuration, not just the number of user messages, and multiply that by your expected peak concurrency. If the result is many times the work a single model call costs, the host is undersized for the design, whatever the hardware specification says.

Do not adopt a fixed threshold from a vendor or a forum. The NeMo Guardrails installation documentation sets a minimum of 1 CPU and 4 GB RAM for the library itself, but the cost that matters is the model served by Ollama, and that depends on your model, quantization, prompt lengths and concurrency. Load-test the exact configuration with a realistic mix of allowed and blocked requests, record p95 latency and queue wait at your target concurrency, and check the Ollama server logs for queued work. If those numbers miss your service targets after tuning the three settings above, plan GPU capacity or a separately hosted model endpoint before go-live.

Securing the Ollama endpoint behind guardrails

Ollama is easy to start and easy to expose by accident, and the guardrails layer only helps if the model endpoint behind it is reachable by the right callers and nobody else. The cards below cover the bind address, the proxy layer, cloud features, credentials, model storage and what Ollama does and does not see.

Keep the default loopback bind

Ollama binds to 127.0.0.1 on port 11434 by default, so only processes on the same machine can reach it. Keep that default unless you have a specific reason to change it. If NeMo Guardrails runs in a container or on a separate host, confirm the network path before changing anything, because a container cannot reach the host's loopback address without extra configuration.

Ollama FAQ

Front OLLAMA_HOST with an authenticated proxy

Changing the bind address through OLLAMA_HOST exposes the local API, and that API has no authentication of its own. If callers on other hosts need access, place a reverse proxy such as Nginx in front of it, enforce authentication and TLS at the proxy, and restrict which networks can reach it. Test that unauthenticated requests are refused before NeMo Guardrails is pointed at the endpoint.

Disable cloud features

Set OLLAMA_NO_CLOUD=1 or turn off cloud features in the server configuration file so the local runtime does not route requests to cloud models. This keeps the endpoint local-only, which matters when the guardrails are meant to keep data inside your environment. Verify the setting on the running server, not only in the file you edited.

Keep cloud API keys out of local configs

Direct cloud inference at ollama.com requires an API key sent as a Bearer token, while the local API does not. Do not place that key in config.yml, Colang files or Python actions that are committed to source control or copied into container images. Load it from your secrets store at runtime and give the NeMo Guardrails service account only the access it needs.

Ollama authentication docs

Restrict model storage paths

Ollama stores models in a default user or system directory, and the OLLAMA_MODELS variable moves them elsewhere. Pick a directory with controlled ownership and permissions, and make sure the service account can read it without being able to modify model files. Confirm the path on each host, because a default location can differ between a workstation and a service install.

Verify your own logging

Ollama states that local runs do not expose your prompts or data to Ollama. That statement covers the vendor, not your own stack. Check what your reverse proxy, container runtime, NeMo Guardrails logs and tracing tools record, including full prompts and responses, and set retention and access rules for those logs before you treat the deployment as reviewed.

Mapping engine settings, endpoints and model roles

This table maps each setting you will touch when pointing NeMo Guardrails at Ollama to its meaning, its source and the party who owns it. Read it before editing config.yml, so the main model and self-check rails are not mixed up with the Ollama server settings on the host.

SettingWhat it controlsSource of the valueWho owns it
Engine nameTells the built-in framework which provider adapter to load for the main modelThe ollama engine in the NeMo Guardrails supported LLMs documentation, set in config.ymlYour team, in the guardrails configuration repository
Base URLWhere NeMo Guardrails sends chat requests, by default the OpenAI-style path on the local serverDefault override only if the Ollama host differsPlatform team, set per environment
Main model nameThe model that answers user requests and runs dialog and generation railsModel tag pulled into the local Ollama model store, for example a name you pulled with the Ollama CLIApplication team, chosen with the model owner
Self-check model nameA smaller model for input and output self-check rails, which can differ from the main modelTag of a second local model, sized to the CPU or GPU available on the hostSecurity or AI platform team, reviewed against rail latency
OLLAMA_HOSTBind address and port of the Ollama server, default 127.0.0.1 on port 11434Ollama FAQ, set as an environment variable on the Ollama hostInfrastructure team running the Ollama service
OLLAMA_MODELSDirectory where model weights are stored, which must have room for every pulled modelOllama FAQ, defaults vary by operating system and can be moved with this variableInfrastructure team, sized to the host disk
API key for local OllamaNot required on the default local endpoint, so the placeholder value is only a configuration detailOllama API authentication documentationApplication team, confirm no proxy adds access control
API key for cloud inferenceBearer token for direct calls to ollama.com endpoints, a separate path from local servingOllama account and API key, sent as a Bearer token per the Ollama API authentication documentationSecurity team, stored in a secrets manager and scoped per application

Questions teams ask before running guardrails on Ollama

What does it cost to run NeMo Guardrails on Ollama?

The software costs nothing to license, and running models on your own hardware carries no per-use fee from Ollama. Your spend falls into three parts: the hardware or cloud compute that runs Ollama and the guardrail checks, the staff time to configure and test the rails, and the recurring cost of keeping the stack patched and monitored. NeMo Guardrails is licensed under Apache 2.0, and Ollama's pricing page states that running models on your own hardware is always unlimited. Cost rises with the number of rails, because each self-check rail can add a model call to every request. Ask any partner for a quote built from a written scope that lists hardware, rail count and test coverage separately.

Do Ollama cloud model plans change the cost of local guardrails?

No. The Ollama plans cover cloud models, and they do not apply to models you run on your own machines. Ollama's pricing page lists Pro at $20 per month ($200 per year), Max at $100 per month, Team at $500 per month and Enterprise at custom pricing. Enterprise adds model access controls, cost budgets per user or API key, a dedicated support channel and custom security options on top of the Team features. Choose a cloud plan only if your design sends inference to ollama.com, and confirm that data path with your security team before you pay for it.

Which factors make the effort larger or smaller?

Effort follows the number of rails, the number of models in the path and the depth of testing. A configuration with a single self-check input rail and one local model is much smaller than one with input rails, dialog rails, output rails and retrieval checks, each calling a different model. Colang choices matter too: Colang 1.0 is the default, and Colang 2.0 needs a deliberate choice and review. Testing scope is often the largest variable, since proving that each rail blocks what it should and allows normal traffic takes data, reviewers and repeated runs. Ask for effort broken out by rail, model, integration and test scope.

Can our own engineers set this up without a partner?

Yes, if your team has Python experience, can run and secure the hosts, and has time to test. The setup is conventional: install the library on Python 3.11, 3.12 or 3.13, point the engine at the Ollama base URL, write config.yml and Colang files, then test. A partner adds value where you lack people to design the rail set, review the Colang logic, write evaluation data, or pass a security review. Many teams split the work, keeping day-to-day configuration in-house and buying a design review, testing or a hardening pass.

What do we need to provide for the work to go smoothly?

You need four inputs: hardware access, model decisions, policy requirements and test data. Hardware access means hosts or VMs where Ollama and NeMo Guardrails can run, with network rules that keep Ollama bound to 127.0.0.1 or a private address behind a proxy. Model decisions cover which local model handles self-checks and which handles the main reply. Policy requirements list what must be blocked, allowed and logged. Test data means representative prompts, including attack and edge cases drawn from real use, which should be handled under your data rules.

When does CPU-only hardware stop being enough?

CPU-only hosts can run the library with a minimum of 1 CPU and 4 GB RAM, but a model used for self-check rails adds a full model call to each request, and that call slows down on a CPU. Latency and concurrency decide the point. Ollama defaults to one parallel request per model (OLLAMA_NUM_PARALLEL) and three loaded models on CPU (OLLAMA_MAX_LOADED_MODELS), so raise those values only after measuring memory use. Test with your chosen model and expected load. If response times exceed your application's limits, add GPU capacity, use a smaller model for checks, or move checks to separately deployed hardware.

How long does a guardrails on Ollama project take?

Duration depends on the number of rails, the quality of your policy and test data, and how many approval cycles your security or compliance teams require. Each new rail type, model and integration adds design and test work, and a first build is usually slower than later changes. No standard duration applies, so ask for a timeline tied to a written scope, with separate milestones for environment setup, rail design, testing and handover. Confirm with your team which reviews must finish before go-live, because those reviews often set the schedule.

How DeployOpen scopes and delivers an Ollama guardrails setup

DeployOpen plans, implements, hardens and supports self-hosted open-source platforms inside the client's own infrastructure, including cloud accounts, data centers and air-gapped networks. DeployOpen is a Chainscore Labs company. For an Ollama guardrails setup, that means the NeMo Guardrails configuration, the Ollama runtime and its model storage, the network path between the guardrails server and the Ollama endpoint, and the logging and access controls around them are all designed and delivered in the environment where they will run. DeployOpen is not an official partner, reseller or certified provider of NVIDIA or Ollama.

Most engagements are fixed-scope. Before work starts, the scope, deliverables and timelines are agreed in writing, and a quote follows from that written scope rather than from a price list, since DeployOpen does not publish one. For this topic, the scope usually needs to name the models to be run, whether self-check rails will use a small local model, whether the Ollama API is reachable only from localhost or through a proxy, the hardware the Ollama host will use, and the test cases that will prove the rails behave as intended. Ask for each of these to be written down, because they determine the effort and whether a larger host is needed.

Ongoing work is handled through retainers that cover support, upgrades and continuous testing. This matters here because NeMo Guardrails releases and Ollama releases both move frequently, so a configuration that works today may need retesting after an upgrade. Confirm with the team, before signing, which parts of the setup are covered by a retainer, how upgrades of each component are tested, and who owns the written scope once the initial build is finished.

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.