Adding NeMo Guardrails to an existing RAG pipeline: what changes and when it is worth it
Adding NeMo Guardrails to a working RAG pipeline means placing it around the code you already have, not rewriting that code. Your retriever and generator stay in place. NeMo Guardrails receives the chunks your retriever returns and the draft answer your generator produces, and it runs checks on each. The change is worth the effort when your team needs grounding checks that can be configured, logged and reviewed outside the application code, or when several assistants need the same rules. If your answers are already sourced and no one has asked for checks on them, the case is weaker and should be argued on specific risks.
NeMo Guardrails is an open-source library licensed under Apache 2.0. It organizes checks into five rail types: input rails that examine the user message, dialog rails that steer the conversation, retrieval rails that validate and filter retrieved chunks, execution rails that wrap custom actions and tools, and output rails that check the generated response. For an existing RAG pipeline, the retrieval and output rails do most of the work. The library runs on Python 3.11, 3.12 or 3.13. The current release is 0.25.0, so confirm that version and its migration notes against your environment before you start.
This page covers the integration decisions: how chunks reach the rails, how to wrap custom retrieval and generation, how LangChain chains fit, and which rails run before retrieval, on chunks and on the answer. It is not a Colang tutorial. Colang syntax, flow design and the upgrade path between Colang versions are covered in other sections. Before committing, ask whether your team will maintain a configuration folder, Python actions and a test suite, since those are the recurring work that follows the initial wiring.
How a RAG request flows through the rails
The request starts with the user's question entering the input rails inside the guardrails runtime, then passes to your retriever in your application. The retrieved chunks return to the runtime for retrieval rails, which filter, validate or mask them before they reach your generator. The generated answer then goes through output rails before it is returned. Check each hand-off, since data crosses the trust boundary twice.
Request path through input, retrieval and output rails, with the application and runtime as separate trust zones.
Integration options and when each fits
This table compares the three ways to connect NeMo Guardrails to an existing retriever and generator: custom RAG actions inside your own application, the LangChain integration, and the guardrails server over HTTP. Read each row as a split of responsibilities, then pick the option that matches where your retrieval and generation code already lives. The main takeaway is that the more of the stack you keep in your own code, the more you own of the wiring that connects retrieval to the rails.
| Option | What you own | What NeMo Guardrails owns | When it fits |
|---|---|---|---|
| Custom RAG action in the Python API | Retriever, vector store, generator call, and the action that returns relevant chunks | Rail execution, retrieval rails on returned chunks, and output rails on the answer | Your app is already Python and you want the rails in the same process with full control of retrieval |
| LangChain integration (opt-in) | LangChain chains, retriever and LLM objects, and the environment variable set at deployment | Guardrail execution around the chain, once the framework flag is enabled | Your RAG pipeline is built on LangChain and you want to keep its chain structure intact |
| Guardrails server over HTTP | Your retriever and generator service, which sends chunks and receives the checked response | Configuration loading from a folder, the HTTP API, and rail execution on each request | Retrieval and generation run in a different service or language from the rails |
| Knowledge base (kb folder) | Markdown documents and their maintenance | Chunking, embeddings and retrieval for the built-in store | Small, mostly static document sets, not an existing vector database |
| Retrieval rails on chunks | Passing the relevant chunks into the rails in the expected shape | Validating, filtering and masking chunks before the prompt is built | Any option above, when retrieved content needs checks before generation |
| Output rails on the answer | Choosing which fact-checking rails to enable and their thresholds | Running the configured checks on the generated answer | Answers must be grounded in evidence before they reach users |
| Engine and version compatibility | Python version on your hosts and the framework version in your chain | Requirements of the NeMo Guardrails release you pin | Confirm the pinned release supports your Python version and framework before choosing |
How your retrieved chunks reach the retrieval rails
Retrieval rails are the NeMo Guardrails rail type that validates, filters and masks retrieved chunks before they enter the prompt, so your application must pass the chunks to the rails on every call. Your retriever stays in your code. NeMo Guardrails does not search your store when you bring your own chunks, so the application is responsible for supplying the right chunks for each user message, in the structure the library expects. Before go-live, confirm in the NeMo Guardrails documentation the exact context key that carries the chunks, the expected fields for each chunk (text and source identifier), and how the rails behave when the list is empty. Test each of these with your installed version, because the names change between releases.
The built-in knowledge base works differently. Documents placed in the kb folder of a configuration are indexed by the library, which handles chunking, embedding and retrieval itself, so the application passes only the user message. That path accepts Markdown only and is designed for small, document-based assistants. With your own pipeline, you decide how documents are chunked, which embedding model is used, which index holds them and how access is enforced. Per-user permissions in your existing store are not carried into the library's index, so filter by the caller's entitlements before chunks are passed. The decision to keep the built-in index or to pass your own chunks should be made before the configuration is written, because it determines who owns retrieval and what must be tested.
Setting up the wrapper around your existing pipeline
This sequence takes your existing retriever and generator and places NeMo Guardrails around them in a way you can test locally and then ship as a server image. Each step closes with a check, so a failed build stops before it reaches production.
Pin Python and the library version
Your platform engineer selects a Python interpreter from the versions NeMo Guardrails 0.25.0 supports, which are 3.11, 3.12 and 3.13, and installs the nemoguardrails package at an exact version in a virtual environment or lock file. Pinning matters because the 0.25.0 release deprecates the LLMRails class in favor of Guardrails, with removal planned no earlier than 0.27.0, so later upgrades need planning. Done when the environment reproduces the same version on a clean machine and the pinned version appears in your dependency file.
Write the config.yml and rail placement
Your engineers create a configuration folder with a config.yml file that declares the model and the rails you need, and decide where each rail runs: input rails before retrieval, retrieval rails on chunks, and output rails on the generated answer. Rail order determines what the user sees, so the team should write down which rail blocks, which one masks, and which one only logs. Done when the file loads without errors and the rail list matches the written placement plan.
Expose retriever output through custom RAG actions
Your developers write a Python action that calls your existing retriever and returns its chunks in the shape the retrieval rails expect, so the rails receive the same evidence your generator uses. Keep the chunk text, source identifiers and any metadata intact, because grounding checks compare the answer against exactly these passages. Done when a test call to the action returns the chunks your retriever returns for the same query, with source identifiers attached.
Decide between Colang 1.0 and 2.0
The team chooses the Colang version for the flow definitions. Colang 1.0 is the default and both versions are supported, so choose 2.0 only if you have a reason to adopt its flow model. If you have existing 1.0 flows, NVIDIA's documented nemoguardrails convert tool can help, but converted configurations still need manual review. Done when the chosen version is written into the configuration and a single sample flow runs under it.
Run a local test with the Python API
An engineer calls the library from Python with a representative query, runs the full path from input rails through your retriever action to the output rails, and reviews the logs for each rail decision. Include at least one query where the retriever returns nothing relevant and one where the generated answer goes beyond the chunks, so you see both outcomes. Done when the test shows the expected blocks, passes and logged decisions, and the answer and rail trace are saved for comparison later.
Start the guardrails server locally
The team runs the same configuration folder as the guardrails server, which loads configurations from a folder and exposes an HTTP API. Send the same test queries over HTTP and compare the responses with the Python API results. Differences usually come from environment variables, model credentials or file paths that the container will not inherit. Done when HTTP responses match the local Python results for the test set.
Build and deploy the server image
Your platform team builds a container image from the Dockerfile that NeMo Guardrails provides, adds your configuration folder and actions, and deploys it to the environment you control. Set the LangChain framework variable only if your chain depends on it, since that integration is opt-in. Confirm that model endpoints, secrets and network paths resolve inside the cluster or host. Done when the deployed service passes the same test set and the image tag, configuration version and library version are recorded together.
Which rails run before retrieval, on chunks and on the answer
Input rails run on the user's message before your retriever is called. They see only what the user typed, plus conversation state when dialog rails are in use. Dialog rails use Colang flows to match intents and steer multi-turn exchanges, for example routing an off-topic question to a fixed reply without touching the vector store. Running them first stops unwanted queries from reaching your retriever and generator, which saves retrieval and model calls. The trade-off is that input checks add a model or classifier call to every request, and an input rail cannot judge evidence it has not yet seen.
- What it sees: the raw user message and, for dialog rails, the flow state of the conversation.
- Main benefit: blocked or redirected queries never reach retrieval or the generator.
- Main cost: each enabled input check adds latency to every request, including harmless ones.
- Ownership: the application team usually writes the Colang flows, while security or product owners approve the blocked topics and wording.
- Confirm: which input checks your traffic needs, the added latency per check in your environment, and whether the classifiers run on your own hardware.
Confirm with the team how many requests each input rail will reject in a test set before you enable it in production.
Retrieval rails run after your retriever returns chunks and before those chunks enter the prompt. They see the retrieved text and the user's query, so they can drop, filter or mask chunks that fail a check. This is the placement where a RAG pipeline gains control over what evidence the model reads. Passing the chunks into the rails requires that your custom RAG action returns them in the shape the rails expect, and the chunk checks depend on the engine and rail configuration you choose. Each check adds work per chunk, so the cost grows with the number of chunks you retrieve.
- What it sees: each retrieved chunk alongside the user query.
- Main benefit: poisoned, out-of-scope or sensitive chunks can be removed before the model reads them.
- Main cost: per-chunk processing that scales with top-k retrieval size.
- Ownership: the data or search team owns chunk metadata and access filters, and the security team usually owns masking rules.
- Confirm: the retrieval rail checks your version supports, the engine requirements for them, and whether masking changes the source text your auditors will compare against.
Confirm with the team whether permission filtering should happen in the retriever itself, since a rail filters only what it receives.
Execution rails wrap custom actions and tools that your pipeline calls, such as the retriever, a database lookup or an internal API. They run around the action rather than on the answer text, so they can check the arguments sent to a tool and the result it returns. For a RAG pipeline, the retriever itself is the most important action to wrap, because its results become the evidence for the answer. Execution rails depend on how your actions are written and registered, so they are part of the build rather than an add-on at the end.
- What it sees: the inputs to an action and the data it returns.
- Main benefit: a single place to validate retriever calls and reject malformed or unauthorized results.
- Main cost: developers must register actions consistently, and every action wrapped adds a call to maintain.
- Ownership: the platform or application team owns the actions, while the security team reviews what each action is allowed to reach.
- Confirm: which actions must be wrapped, how the retriever's output is passed back, and whether action failures should block the answer or fall back.
Confirm with the team how custom actions will be tested in isolation before they are connected to the full RAG flow.
Output rails run on the generated answer before it reaches the user. In a RAG pipeline this is where grounding checks such as self-check fact-checking or hallucination detection compare the answer with the chunks that were retrieved. Output rails also cover content safety and blocking, so an answer can be refused or replaced with a fixed message. Grounding checks need the evidence and the answer together, which is why the pipeline must pass the chunks through to this stage. These checks usually cost the most, because they often call a language model or a separate scoring model after generation has already run.
- What it sees: the generated answer and, for grounding checks, the retrieved chunks.
- Main benefit: unsupported or unsafe answers can be caught before the user sees them.
- Main cost: added latency after generation, plus extra model calls for each grounding check.
- Ownership: the application team owns the grounding logic, while the risk or compliance owner decides whether to block or warn.
- Confirm: which grounding check fits your accuracy and latency needs, where the checking model runs, and what a blocked answer should show the user.
Confirm with the team whether a failed check returns a refusal, a warning or the original answer, because each choice changes the user experience.
Security and operational considerations for the wrapper
A RAG wrapper around NeMo Guardrails touches retrieved data, credentials, a network API, logs, configuration and dependencies at once. The six concerns below are the ones to settle before the wrapper reaches production, and each one needs an owner and a written decision.
Personal data in retrieved content
Retrieved chunks enter the prompt and can carry personal data from your document store, even when the user's question does not. Decide whether chunks are filtered, masked or blocked before they reach the model, and where that check sits in the wrapper. Confirm with your privacy team which fields count as personal data in your corpus, and test with sample documents that include names, account numbers and identifiers.
Credentials held by custom actions
Custom actions that call your search index, ticketing system or internal APIs need credentials, and those credentials must not appear in the Colang files, the config folder or the prompts. Load them from your secrets manager or environment at runtime, scope each one to read-only access where possible, and rotate them on your normal schedule. Ask who can read the process environment of the server container.
HTTP API exposure of the server
When you run the guardrails server, it exposes an HTTP API that any service on the network can call, so the server is an access point to your model and your retrieval path. Place it behind your gateway or service mesh, restrict callers by network policy and authentication, and do not publish it directly. Confirm the authentication options in the current release documentation before you commit to a design.
NeMo Guardrails docsLogging blocked and passed content
Logs of blocked and passed requests are useful for debugging but can store the user question, the retrieved chunks and the generated answer together, which is personal data in many settings. Decide what is logged at each rail, how long logs are kept, and who can read them. Confirm what the library logs by default and what your wrapper adds, and test that logs do not hold secrets from actions.
Access to configuration files
The config.yml file, Colang files and Python actions define which rails run and how the application behaves, so changes to them change safety outcomes. Store them in version control, require review for changes, and limit write access to the team that owns the rails. Make sure the running server reads only the approved folder and that deployed configurations match the reviewed commit.
Keeping the library patched
Your wrapper depends on the nemoguardrails package and its own dependencies, and the package is released under Apache 2.0 with new versions published over time. Pin the version you tested, track release notes, and plan upgrades as a test cycle that reruns your rail checks. Note that the LLMRails class is deprecated in 0.25.0 in favor of Guardrails, so check your wrapper against the 0.25 migration guide before upgrading.
Release notesQuestions teams ask before wrapping an existing RAG pipeline
Can our own team add NeMo Guardrails to our RAG pipeline without a partner?
Yes, if your team already runs Python services and can own a Colang or YAML configuration, and has someone who understands your retriever and prompts. The library is a Python package installed with pip, and its rails wrap calls you already make. Teams usually struggle less with installation than with deciding which rails to run, how to pass retrieved chunks into the rails, and how to prove the configuration blocks what it should. Ask whether anyone on the team has time to build an evaluation set and tune thresholds over several rounds, because that work tends to take longer than the wiring itself.
What drives the effort of adding guardrails to a RAG pipeline?
Effort rises with the number of rails and how much custom code they need. The main drivers are:
- The number of rails enabled, especially retrieval rails, output rails and any fact-checking rail that makes extra model calls
- Custom actions that call your internal systems, identity checks or domain-specific validators
- Colang choice: Colang 1.0 is the default, and Colang 2.0 is a separate design with its own migration work if you have existing 1.0 files
- Deployment target: a Python library inside your app differs from a guardrails server in a container, and both differ from a Kubernetes rollout with air-gapped model endpoints
- How much of your retriever and generator you need to wrap, and whether LangChain chains are involved, which is opt-in through the
NEMOGUARDRAILS_LLM_FRAMEWORK=langchainsetting
How long does it take to wrap an existing RAG pipeline?
Duration depends on scope, and no timeline applies to every pipeline. A single retrieval rail on one retriever with a basic output check is a small change. A pipeline with several rails, custom actions, a Colang migration and a deployment to your own cluster is a larger project with testing and review stages. Ask any provider, including us, to break the schedule into design, build, evaluation and rollout, and to state which of your systems and approvals each stage depends on. Access to your retriever test environment and your security review calendar usually set the pace more than the code does.
What must our team provide before the work starts?
Plan to provide access and data before the build begins. Typical inputs include:
- Read access to the retriever in a non-production environment, with the metadata fields that identify source documents
- A sample of representative user queries and the answers your application should give
- Evaluation data: questions with known answers, questions that should be refused, and examples of off-topic or unsafe requests
- Model endpoints and credentials for the generator and any judge or safety model you plan to use
- Named owners for security review, compliance sign-off and on-call support
Without evaluation data, thresholds cannot be tuned, so ask for this input explicitly in any quote.
Does NeMo Guardrails itself cost anything to use?
The library is licensed under Apache 2.0, and the nemoguardrails package on PyPI is free to download and use under those terms. Your costs come from infrastructure and model calls. These include compute for the guardrails process, any self-hosted safety or fact-checking model, and the tokens your generator and judge models consume, since some rails make extra LLM calls per request. Confirm the license terms of any model or third-party integration you add, because those carry their own terms. The NVIDIA NeMo Microservices sunset is a separate matter, so check your deployment path before you plan around the container.
When does a fixed-scope engagement make sense for this work?
A fixed-scope engagement fits when you can name the rails, the retriever and the deployment target before the work starts. DeployOpen agrees scope, deliverables and timelines in writing before work begins, and quotes follow from that written scope. It is a poor fit when the rails are still undecided or the evaluation data does not exist yet, because the scope will shift as the team learns. In that case, start with a short design phase, then fix the build scope once the rail list and evaluation set are agreed. Ongoing tuning, upgrades and continuous testing can be handled as a retainer after the build.
How DeployOpen scopes this integration
DeployOpen starts every NeMo Guardrails integration with a written, fixed scope that is agreed before any work begins. For an existing RAG pipeline, that scope names the retriever you already run, the generator the application calls, the rails that will execute, the custom actions that will be written, and the systems the wrapper must reach. It also records what is out of scope, such as changes to your vector store, your embedding pipeline or your application front end. Deliverables and acceptance checks are listed in the same document, so your team can see what it receives before committing budget. Pricing follows from that written scope and is not published as a list.
The most important planning artifact is the retriever contract. Before implementation, DeployOpen and your engineers agree on what the retrieval step hands to the rails: the chunk text, source identifiers, relevance scores, document permissions and metadata needed for citation. The team also decides which rails run before retrieval (for example, input checks on the user message), which run on the retrieved chunks, and which run on the generated answer. Each choice affects latency and where a blocked response is logged. Your team should confirm how your retriever already returns metadata, because a missing source identifier can make fact-checking and audit trails harder to build later.
Implementation runs in your own infrastructure, using the cloud accounts, data centers or air-gapped networks you control. The wrapper is built against the configuration format of the NeMo Guardrails release you select, and DeployOpen tests it with your real retrieval results, including empty results and malformed chunks. Testing covers the rails, the custom actions, the server or Python API you expose and the logging needed for review. Because the library's release line is still moving, the engagement also records the pinned version, the Python version and the upgrade notes that apply to it. After handover, a retainer can cover version upgrades, configuration changes after new rails are added and continued testing, so the integration does not drift from your pipeline.
How DeployOpen delivers NeMo Guardrails integrations
DeployOpen approaches adding NeMo Guardrails to an existing RAG pipeline by first fixing what your retriever returns, what the generator receives and where each rail sits in the request path. We then build and test the integration in your own infrastructure and hand over the configuration, actions and runbooks your team needs to operate it.
How we scope
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
- We map your retriever, chunk format, generator and any LangChain chains to the rails that will run on each stage.
- We confirm the NeMo Guardrails version, Python version and whether your integration uses Colang 1.0 or 2.0 before build.
How we build
- We wrap your existing retriever and generator with a custom RAG action that passes relevant chunks into the rails.
- We configure input, retrieval, execution and output rails in config.yml and Colang files, enabling only the checks your use case needs.
- We test each rail against representative queries and retrieved chunks, including empty retrieval and conflicting sources.
How we hand over
- We deliver the configuration folder, Python actions, deployment artifacts and a written record of which rails run before retrieval, on chunks and on the answer.
- We document the LangChain opt-in setting and any migration steps, and we note where converted configurations still need manual review.
- We provide runbooks covering how to read blocked responses, update rails and roll back a configuration change.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, which cover NeMo Guardrails version changes after handover.
- We plan upgrades against the release notes and breaking changes for each NeMo Guardrails version before applying them.
- Ask us to confirm in the quote which support hours, response expectations and retest cycles the retainer includes.

