When should teams cache guardrail model calls in NeMo Guardrails?
Teams should cache guardrail model calls when their NeMo Guardrails deployment sees the same or near-identical inputs repeatedly and each check calls a NemoGuard safety model. NeMo Guardrails has an in-memory LFU (least frequently used) cache for these model calls, which is part of the library runtime, not a separate service. It stores the results of recent calls to NemoGuard models so that a repeated check on identical input can be answered from memory instead of running the model again. The cache helps most when a platform team runs guardrails in front of a customer-facing assistant that receives common greetings, templated questions, or repeated attacks from automated scanners, and when the same content passes through several rails in one request.
Repeat traffic is the condition that decides whether the cache is worth enabling. It will do little for workloads where nearly every prompt is unique, such as long free-text conversations, documents passed through retrieval rails, or model outputs that differ on each run, because misses cost the same as no cache. It also does not remove the cost of the first call for any input, and it does not change which rails run. Before turning it on, measure the share of safety checks whose inputs repeat within the time a cached entry would survive, using your own logs or a replay of recent traffic. Confirm the exact configuration keys, cache size and default values in the NeMo Guardrails documentation for the version you run, since these settings are not fixed here and may change between releases.
Caching also has a limit that matters for production design. An in-memory cache is local to each process, so when you run several guardrail server replicas behind a load balancer, each replica builds its own cache, and hit rates depend on how requests are routed. A cache also keeps results from earlier calls, so after a model or configuration change, confirm how entries are invalidated and whether a restart clears them. Plan to read hit and miss telemetry from the library before and after enabling the cache, and treat the cache as a latency measure that must be verified, not assumed, under your own traffic.
Cache configuration options and when each fits
This table compares the settings a team decides before turning on the in-memory cache for NemoGuard model calls, what each one controls, and the signal that it needs changing. Read the memory versus hit rate trade-off first, then confirm exact setting names and defaults in the configuration reference for your NeMo Guardrails version. The main takeaway is that a larger cache only pays off when inputs repeat, and each server replica keeps its own copy.
| Setting | What it controls and the trade-off | Change it when |
|---|---|---|
| Cache enabled for NemoGuard models | Decides whether repeated safety model calls reuse stored results. Enabling it uses memory but can skip model calls for repeated inputs. | Logs show many identical inputs passing through the same safety model. |
| Maximum cache size | Caps how many results stay in memory. When full, least frequently used entries are evicted. Larger sizes raise hit rate but use more memory. | Miss rate stays high with frequent evictions, or the container is under memory pressure. |
| Per-model cache switch | Lets you cache some NemoGuard models and not others. Cache models with repetitive inputs and skip those where verdicts must track policy changes. | One model fills most of the cache, or a model's verdicts must reflect the latest policy. |
| Statistics output | Reports hits, misses and evictions so you can judge whether the cache helps. Adds a small amount of logging overhead. | Before sizing the cache, or when you need evidence that caching reduces model calls. |
| Hit and miss telemetry in metrics | Exposes hit ratio per model to dashboards and alerts. More labels mean more metric series and higher monitoring cost. | Dashboards must show hit ratio per model, or hit rate drops without explanation. |
| Cache scope per replica | Each server process holds its own in-memory cache, so replicas do not share results. Hit rate tends to fall as replica count rises. | You scale horizontally and measured hit rate drops after adding replicas. |
| Cache reset on reload or restart | Confirm in the reference whether a configuration reload or restart clears the cache. A cleared cache starts cold and misses until it refills. | You reload configurations often and see a miss spike after each change. |
How cache hits and misses flow through a guardrail call
The request starts at a client calling the guardrails server, where the input rail calls a NemoGuard model. Before the model endpoint is reached, the call checks an in-memory LFU cache that lives inside one server process. A hit returns the stored result, while a miss calls the model endpoint and stores the result for later calls. Check that every replica behind a load balancer has its own cache, so a hit on one replica does not help another.
Cache hits skip the model call, while misses call the endpoint and store the result.
How to enable and verify the model call cache
This sequence turns on the model call cache for NemoGuard calls in NeMo Guardrails and proves with a repeated test request that hits are recorded. It covers version checks, configuration, a restart, a repeated request, reading statistics and a multi-instance check, with a rollback path at each point where the result can fail.
Confirm the NeMo Guardrails and Python versions
The engineer running the service checks the installed package with
pip show nemoguardrailsand the interpreter withpython --version. NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13, so the environment must match before any cache setting is tested. Review the release notes for the version you run, because cache options can change between releases. Done when both outputs match your target. If the package is older than the version you plan to validate, upgrade in a test environment first and repeat this step before changing production.Identify the NemoGuard model calls to cache
The platform owner lists every rail in
config.ymlthat calls a NemoGuard model, such as topic control, jailbreak detection or content safety. The model call cache covers calls to those models, so rails that call a general LLM or a third-party moderation API need a separate check in the documentation. Record which rails call which endpoints, and note any prompt fields that vary per request, such as user IDs, timestamps or session tokens, because those values make otherwise identical requests differ and lower hit rates. Done when you have a short list of eligible rails and a note of the variable fields.Set the cache options in configuration
The engineer adds the cache settings to
config.ymlor, for embedded use, to the configuration object passed to the Python API. Confirm the exact option names, size and any statistics setting against the NeMo Guardrails documentation for your version, because this page does not list them and names can differ between releases. Use a modest size for the first test and write down the values chosen. Done when the configuration loads in a test environment with no configuration error. Keep the file in version control so the change can be reverted in one step.Restart the server or process
Restart the guardrails server, or the application process that imports NeMo Guardrails, so the new configuration is read. The cache lives in memory, so a restart also empties it and gives the test a clean starting point. Use the same restart method as production, such as your container orchestrator or process manager, so the test reflects how the service runs. Done when the service reports healthy and the logs show that it loaded the updated configuration. Rollback: if the service fails to start, restore the previous configuration from version control and restart again.
Send an identical request twice
Send the same test prompt to the guardrails endpoint or Python call twice in succession, using identical text, roles and model settings. Choose a prompt that triggers a NemoGuard rail from the earlier list, and label it as illustrative in your test plan. If the cache applies to that rail, the first request should miss and the second should hit. Done when both responses match and the statistics in the next step show one miss followed by one hit. If the responses differ, check whether any prompt field changed between the two calls.
Read cache statistics and confirm hits
Read the cache statistics exposed by your installed version, through the API or the logs, and record the hit and miss counts before and after the test. Confirm the statistics interface in the documentation for your version. Expect the miss count to rise on the first request and the hit count to rise on the second. Done when the hit count increases after the repeat. Rollback if the statistics show no change: confirm the cache is enabled in the loaded configuration, the rail calls a NemoGuard model, the input text is byte-identical, and the statistics come from the process that served the request, then retest. If the problem persists, disable the cache, restore the previous configuration and record the version details for a support request.
Check cache behavior across replicas
If the service runs more than one instance, send the same repeated request to each instance and read the statistics from each one. The cache is held in memory in each process, so hits recorded on one instance do not appear in another instance's counts. A request routed to a different instance can miss even after the first instance cached the same input. Done when you can describe hit behavior per instance and have confirmed the routing rules in your load balancer or gateway. Record this result before relying on the cache for capacity planning.
Security and data risks of caching model calls
A model call cache trades latency for a new place where prompts, verdicts and personal data sit. The risks below connect because they all depend on what the cache stores, where it lives, how long it survives and who can read it.
Personal data held in memory
A cached entry can hold the user prompt or model output that a safety check saw, including names, account numbers or health details. That data stays in process memory until it is evicted or the process stops. Confirm which fields the cache key and value contain for each NemoGuard model call, and decide whether inputs with personal data should be cached at all. Limit who can reach the host, its memory dumps and its debug output.
Contents may survive restarts
Treat the in-memory cache as something that may not be cleared on restart unless your deployment clears it. Confirm the default behavior with the NeMo Guardrails documentation and your own tests before you rely on it. If the cache is cleared on restart, your rollout procedure should still restart every replica during a policy change so no stale state remains. Document the restart and clearing steps as part of the release runbook.
NeMo Guardrails docsStale safety verdicts after changes
A cached verdict reflects the model and policy that produced it. After you change a safety model, a prompt, a Colang flow or a threshold, a cache hit can return the old decision and let content through or block it wrongly. Confirm whether cache keys reflect the model version and configuration. Clear or invalidate the cache as part of every model and configuration change, and rerun your test set against cached paths to confirm the new behavior.
Prompt fragments in statistics and logs
Hit and miss counters are safe to expose, but debug logs, traces and error messages can echo the text being checked. Those records often reach shared dashboards and log platforms with wider access than the application. Set log levels for production so model inputs are not written in full, and confirm what your telemetry pipeline stores and for how long. Restrict access to the metrics endpoint and any log store that receives guardrail traces.
Cross-tenant cache sharing
When one guardrails process serves several customers, departments or tenants, a shared cache can return a verdict computed from one tenant's input to another tenant's request. Even an identical sentence may carry different meaning or data sensitivity across tenants. Where the cache does not separate tenants, run a separate guardrails instance per tenant or disable caching for tenant-scoped traffic. Confirm with the vendor whether tenant identifiers can be part of the cache key in your version.
Memory exhaustion from a large cache
An unbounded or oversized cache grows the memory use of each replica, and a container that runs out of memory can restart and drop in-flight requests. Set a maximum cache size deliberately and size it against your container memory limit, leaving headroom for model runtimes. Watch memory use per replica over time and alert before it approaches the limit. Ask your team to test peak traffic with the cache filled, not only with an empty cache.
Caching choices for single instance and scaled deployments
With one guardrails process on one host, the in-memory LFU cache is shared by every request that process handles, so repeated safety checks on identical text can be served from memory. The gain depends on how often the same inputs or outputs recur, such as templated greetings, repeated support questions or client retries after a timeout. Treat the cache as a way to speed up repetitive traffic, and measure the hit rate before you count on it.
- Hit rate on your traffic: Replay a sample of recent prompts and model outputs through the process and read the hit and miss counters to see what share repeats.
- Cache size against memory: Set the size from the memory the host can spare after the model endpoint client, the application and the operating system; confirm the size option and eviction behavior in the documentation for your release.
- Statistics visibility: Confirm that cache statistics reach the logs or metrics you already collect, so a slow response can be traced to a miss.
- Restart behavior: An in-memory cache starts empty after every restart or deploy, so measure latency once the cache has warmed up.
- Cache scope: Confirm which rail model calls go through the cache, such as input checks, output checks or both.
Before relying on the cache, confirm with the platform owner that the host has memory headroom for the size you choose and agree with the application team how cached safety results will be logged.
With several replicas behind a load balancer, each replica keeps its own cache. A repeated prompt is a hit only when the load balancer sends it to a replica that has already checked it. Round-robin or least-connections routing spreads repeats across replicas, which lowers the combined hit rate compared with a single process. Session affinity can keep repeats on one replica, but it changes how load is distributed.
- Per-replica counters: Read hit and miss statistics from every replica and aggregate them, since one replica's numbers can look healthy while the fleet's do not.
- Balancing policy: Ask the load balancer owner which algorithm applies and whether affinity is available, and check whether affinity keyed on a user or conversation identifier concentrates load on a few replicas.
- Memory multiplied: Each replica pays for its own cache, so total cache memory is the per-instance size multiplied by the replica count.
- Identical configuration: Replicas running different configurations or model versions can return different cached results, so keep the deployed settings identical across the fleet.
- Rotation and rolling updates: A replica removed from rotation takes its cache with it, and the replacement starts cold.
Before sizing, confirm with the load balancer team which routing and affinity options they support, and confirm with the owners of the safety model endpoints which rate limits and timeouts apply when replicas send duplicate calls.
In a Kubernetes deployment with horizontal autoscaling, new pods are added under load, and each starts with an empty cache. Scale-out events therefore add cold misses at the moment traffic is highest, and scale-in discards cached entries. Because the replica count changes over time, size the cache and the model endpoint capacity for both the peak and the quiet periods rather than for an average.
- Cold-start cost: Each new pod sends model calls for its first requests, so consider readiness gating and warm-up traffic, and confirm the approach with the platform team.
- Autoscaling signal: If the autoscaler reacts to CPU, cache hits reduce CPU use, which can change when scaling happens; test scaling behavior with the cache enabled.
- Pod memory limits: Include the cache size in memory requests and limits, since an out-of-memory termination restarts the pod and empties its cache.
- Per-pod telemetry: Export hit and miss counters for each pod to Prometheus or your collector, and group dashboards by deployment so cold-start misses can be separated from steady-state misses.
- Cache sharing: An in-memory cache is local to each process, so confirm with the team whether the release offers any shared or external cache option before assuming one.
Before finalizing the autoscaling policy, confirm with the owners of the safety model endpoints whether their capacity and rate limits can absorb the miss bursts that occur during scale-out.
What does caching guardrail model calls cost and require?
How much effort does it take to enable and verify the guardrail model cache in-house?
Enabling the in-memory LFU cache for NemoGuard models is a configuration change, but verifying it is the real effort. Your team must confirm which model calls are cached, set a cache size that fits the memory available on each service instance, and check hit and miss telemetry under realistic traffic. The bigger task is proving that a cached verdict is still valid for the request it is reused on. Effort grows with each step you have to test, so ask a partner for a written breakdown of those steps rather than relying on a single estimate.
What factors make the caching work larger or smaller?
Three factors drive most of the effort:
- The number of NemoGuard models in use, since each model type has its own inputs, outputs and verdict behavior to check.
- The replica count, because each instance keeps its own in-memory cache and results can differ across replicas.
- Test coverage of stale-verdict risk, meaning how thoroughly you check that a reused verdict does not allow content that a fresh call would block.
A small deployment with one model and one instance is a far smaller task than a horizontally scaled service running several safety models. Confirm your counts before asking for a quote.
Can our own engineers set up model call caching without outside help?
Yes, a team with working knowledge of its NeMo Guardrails configuration and its deployment can enable the cache and read the statistics. The work that most often needs experienced review is the verification: confirming hit rates are meaningful, that cache keys match what your rails actually send, and that the cache behaves correctly on each replica. Check whether your engineers have time to run that testing and to document the results for security and compliance reviewers. Many teams do the configuration in-house and bring in outside help only for the review.
What does DeployOpen need from us to scope a caching engagement?
A scope is easier to write when the inputs are complete. DeployOpen would ask for:
- Your NeMo Guardrails configuration files, including config.yml, Colang files and any custom actions.
- Representative traffic samples, with personal data removed, so hit and miss behavior can be assessed.
- Your deployment topology, including replica count, scaling rules, and whether instances share any state.
- Model endpoint details for each NemoGuard model, including where it runs and who operates it.
With these inputs, the written scope can state what is covered and what is excluded.
How long does caching work take, and what changes the timeline?
The timeline depends on scope, not on a fixed number of days. A single-instance setup with one model and a clear configuration is a smaller piece of work than a multi-replica service with several safety models, custom actions and a required test plan. Other factors include how quickly your team provides configurations and traffic samples, how many environments must be verified, and whether security or compliance reviewers need written evidence. Ask for a timeline in the written scope, with the assumptions behind it listed.
What is one-time work and what recurs after the cache is running?
The initial configuration, sizing and verification are one-time work. Recurring work includes monitoring hit and miss telemetry, watching for memory pressure, and re-tuning cache size as traffic changes. Any change to a NemoGuard model, a NeMo Guardrails version or a prompt can change verdicts, so the stale-verdict testing needs to be repeated for those changes. Ask any partner whether re-verification after upgrades is included in the initial scope or offered as an ongoing retainer.
Does caching reduce the security risk of guardrail decisions?
Caching is a performance decision, and it does not make guardrail verdicts more accurate. A cached result can be stale if the model, the rail configuration or the input context has changed, and a reused verdict may allow content that a fresh model call would block. Confirm with your security team which rails are safe to cache, how cache entries are invalidated after a configuration change, and what evidence they need before approving the setting. Keep records of these decisions for audit reviews.
How DeployOpen scopes and delivers guardrail caching work
DeployOpen approaches caching of guardrail model calls in NeMo Guardrails as a written, fixed-scope piece of platform work inside your own infrastructure. We agree which NemoGuard models get cached, how cache size and statistics are read, and how hit and miss telemetry reaches your monitoring before any configuration changes.
How we scope
- Inventory which guardrail model calls repeat and which carry sensitive inputs that should not be cached.
- Record the NeMo Guardrails version and deployment mode (Python API or guardrails server) the cache will run in.
- Agree cache size targets, telemetry fields and the scaling limits your team must accept, in writing.
How we build
- Configure the in-memory LFU cache for the agreed NemoGuard models in a staging copy of your configuration.
- Test cache hits and misses against representative traffic and confirm guardrail decisions match uncached runs.
- Wire statistics and hit and miss counters into your existing dashboards and alerts for review.
How we hand over
- Deliver the configuration files, a runbook for cache sizing and reset, and the telemetry definitions used.
- Document the horizontal scaling limits, so each replica's cache behavior is understood by operators.
- Walk your platform and security teams through the test evidence and the open items for their sign-off.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Re-test caching behavior when NeMo Guardrails releases change configuration or cache handling.
- Confirm with your team the NeMo Guardrails release line and Python version your environment supports before each change.

