What the NeMo Guardrails and LangChain integration covers
If you already run a LangChain chain or a tool-calling agent and need checks on user inputs, model outputs and tool calls, the NeMo Guardrails and LangChain integration lets you add those checks without rewriting the application. The integration is opt-in: it is enabled by setting the NEMOGUARDRAILS_LLM_FRAMEWORK=langchain environment variable, so teams running NeMo Guardrails without LangChain do not load it. Plan that setting into your container images, deployment manifests and test environments from the start, because a missing variable is an easy way to get a guardrail configuration that appears to load but does not behave as expected.
The integration covers three patterns. RunnableRails wraps an existing LangChain chain or runnable so that inputs and outputs pass through rails before and after the model call. Agent middleware applies rails around a tool-calling agent, so tool calls and tool results can be checked before the model acts on them. Chains can also be called as guardrail actions, letting an organization reuse an existing LangChain chain as a custom check, such as a classifier prompt or a policy lookup, inside a rail. Choose the pattern by asking where the risk sits: at the chat boundary, at the tool boundary, or in a specific check you already built. Each pattern has its own configuration and its own failure modes, so the choice should be made before the build starts.
Review is part of the design. LangSmith tracing can record the calls that rails block and allow, which gives security and application teams evidence for tuning rails and for answering questions about specific interactions. Before build, confirm the exact class names, method signatures and supported LangChain package versions against the current NeMo Guardrails documentation, since these change between releases and the current library version is 0.25.0. Also confirm which Python version your environment uses, because 0.25.0 requires Python 3.11, 3.12 or 3.13. Treat those checks as part of the scoping work, not as a detail for the developer to resolve later.
Prerequisites for the NeMo Guardrails and LangChain integration
Most delays in a LangChain integration come from versions and deployment choices made late. Confirm the items below before scoping the build, because each one changes how the rails, the model connection and the trace review are set up.
NeMo Guardrails 0.25.0 on a supported Python
Plan around the current library release, 0.25.0, which requires Python 3.11, 3.12 or 3.13. Confirm that your runtime image, build pipeline and developer machines use one of these versions before you pin dependencies. The previous release was 0.24.1, so check whether your existing guardrail code depends on behavior that changed between them. The deprecation of the LLMRails class in favor of Guardrails also affects code written against earlier releases.
PyPI packageLangChain packages your application already uses
List the LangChain, LangChain community and model provider packages your application pins today, along with the versions. NeMo Guardrails' LangChain integration is opt-in, enabled through the NEMOGUARDRAILS_LLM_FRAMEWORK=langchain environment variable, so the framework setting must match the stack you run. Confirm current LangChain compatibility in the NeMo Guardrails release notes before you pick versions, since the two projects release on their own schedules and a mismatch often surfaces only at runtime.
Release notesModel endpoint access and credentials
Identify every model endpoint the rails will call: the main application model, any self-check model and any safety classifier. Confirm network routes from the runtime to each endpoint, the credentials each one needs, and where those secrets are stored and rotated. A guardrail that cannot reach its safety model will fail in a way that affects every request, so test each endpoint from the same environment that will run the application.
Library or server deployment decision
Decide whether guardrails run in-process through the Python API or as a guardrails server that loads configurations from a folder and exposes an HTTP API. The in-process option keeps the rails inside the LangChain application, while the server option gives several applications one shared configuration and a single place to change rules. Build a server image from the provided Dockerfile only if your team will own its upgrades. This choice drives how configurations are versioned and how the trace data is collected.
NeMo Guardrails repositorySunset of the NeMo Guardrails microservice
NVIDIA has sunset the NeMo microservices, and the NGC container for the NeMo Guardrails microservice is no longer supported. Do not base the integration on that container. Start from the open-source library or the guardrails server package, and ask your NVIDIA account team what the sunset means for any existing deployment. Record this decision in the architecture document so that auditors and future maintainers can see why the container was not used.
Sunset noticeLangSmith account and project for traces
If blocked and allowed calls will be reviewed in LangSmith, confirm who owns the account, which project receives the traces and who can read them. Traces can include prompts, retrieved content and tool arguments, so decide the retention period and access group before the first run. Check whether the traces contain personal data that your privacy and records policies must cover. If traces are not kept, document that choice and how blocked calls will be reviewed instead.
How a request moves through rails and the LangChain chain
A user message enters the application and passes the input rails before it reaches the LangChain chain or agent. Tool calls and model output then pass the tool-call and output rails before the answer returns to the user. The LangSmith trace and the model endpoint sit outside the application network, so check which hand-offs carry prompts, completions and tool arguments across the trust boundary.
Request flow through NeMo Guardrails rails, the LangChain chain and the trust boundary.
Setup sequence for adding NeMo Guardrails to LangChain
This sequence takes an existing LangChain application from no guardrails to a tested setup where allowed requests pass and blocked requests return the configured refusal. Each step ends with a check you can run before moving on. The order matters because the LangChain opt-in must be in place before the integration loads.
Install the library in the application environment
The application engineer installs the nemoguardrails package into the same Python environment that runs the LangChain application, using Python 3.11, 3.12 or 3.13. Pin the version you tested, and record it in the project's dependency file. The current release is 0.25.0, so confirm that this version fits your organization's change process before pinning it. Done is confirmed when the package imports cleanly and reports the pinned version inside the application's environment.
Enable the LangChain opt-in
Set the environment variable NEMOGUARDRAILS_LLM_FRAMEWORK to langchain in every place the application runs, including local shells, CI jobs, service definitions and container images. The integration is opt-in, so an application that skips this variable will not use the LangChain path. Platform engineers should add it to the deployment manifest rather than relying on a developer's shell profile. Done is confirmed when startup code reads the variable back and the value is langchain in each environment.
Write the config.yml with model and rails
Create a configuration folder with a config.yml that names the main model and the input and output rails you need. Keep the model settings in this file so the same rails can run against a different model later. Model credentials should come from environment variables or your secret store, not from the file. Done is confirmed when the Python API loads the folder and builds a rails object without a configuration error.
Add Colang flows and Python actions
Add Colang files for the dialog flows and refusal messages the application needs, and add Python actions only for checks that cannot be expressed in the flows, such as a call to an internal policy service. Colang 1.0 is the default, so state the version explicitly in the configuration if your team is standardizing on Colang 2.x. Done is confirmed when every flow and action name referenced in the rails loads, and each custom action returns its expected value when called directly in a unit test.
Wrap the chain with RunnableRails or middleware
The engineer wraps the existing chain with RunnableRails, or attaches agent middleware if the application uses a tool-calling agent, so input and output rails run around the chain without rewriting it. Confirm the exact class names and call signatures in the current NeMo Guardrails documentation for the LangChain integration before coding against them. Done is confirmed when the wrapped chain accepts the same input and returns the same output shape as the unwrapped chain.
Run allowed test inputs
The QA or security engineer runs a fixed set of ordinary requests through the wrapped chain and records the responses. These tests show that the rails do not block legitimate use. If you have enabled tracing, confirm the trace shows each rail that ran for each request. Done is confirmed when every allowed input returns an answer that matches the expected behavior and the trace records the rails evaluated.
Run blocked test inputs
The security engineer runs a fixed set of inputs that should be refused, such as prompt injection attempts and out-of-scope requests, and checks that each returns the refusal defined in the configuration. Confirm that blocked requests do not reach the main model, using a stub model in tests or the trace for live runs. Keep both test sets in source control so they run again after every configuration change. Done is confirmed when every blocked input returns the configured refusal and no call reaches the model.
Choosing between middleware, RunnableRails and chain actions
Agent middleware and tool rails suit applications where a model decides which tools to call and acts on the results. The guardrails sit around the agent loop, so the tool calls the model proposes and the tool outputs it reads can both be checked before anything runs or reaches the model. Most of the application change is in how the agent is built and invoked, while the policy lives in the rail configuration.
- What it wraps: the agent's model calls and tool invocations, including the arguments the model proposes and the results returned to it.
- Code change: the agent is constructed through the integration's middleware entry point, and existing LangChain tool definitions are kept as they are.
- Typical checks: allowed tool names, argument validation, and blocking or redacting sensitive tool results before the model reads them.
- Effort driver: the number of tools and their side effects, since each write action needs its own permission and validation logic.
- Watch: whether your agent loop style and streaming behavior are covered by the release you pin.
Before choosing this path, confirm the exact middleware entry point, the supported LangChain versions, and the tool-call and tool-result rail types in the current documentation.
RunnableRails wraps an existing LangChain runnable, such as a chain or an LCEL pipeline, in a guardrails layer. It fits teams that already have a working chain and want input and output checks without redesigning the chain itself. The wrapped object keeps its calling interface, so most callers continue to invoke it in the same way.
- What it wraps: a runnable that already exists, with rails applied to the input going in and the output coming back.
- Code change: the chain is passed into RunnableRails together with a rail configuration, and the call site uses the wrapper in place of the original chain.
- Scope limit: the rails see what the wrapped runnable receives and returns, so checks on intermediate steps need a different design.
- Runtime setting: the LangChain opt-in,
NEMOGUARDRAILS_LLM_FRAMEWORK=langchain, must be set in every process that uses the wrapper. - Watch: how streamed responses are checked, since output rails may need the full response before they can decide.
Confirm the rail configuration format for your pinned version and test a streaming path before you commit the chain to production.
This pattern runs a LangChain chain as a custom action invoked from inside a Colang rail flow. The chain becomes one step in the guardrail decision, for example a classifier or a grounding check that returns a verdict. The rail flow decides the outcome, and the chain only supplies the verdict the flow branches on.
- What it wraps: a chain used as a decision step, not as the application's main answer path.
- Code change: a Python action is registered with the configuration, calls the chain, and returns a value that the Colang flow uses to allow, block or rewrite the message.
- Good fit: specialized checks that are easier to express as a prompt or chain than as fixed rules.
- Cost driver: each chain call is an additional model call, so latency and token use grow with every check added to the flow.
- Watch: the Colang version. Colang 1.0 is the default, Colang 2.x is supported, and converted configurations still need manual review.
Before building, confirm the action registration method and the Colang syntax for your version, and measure the added latency on representative traffic.
How LangChain messages and tool calls map to rail inputs and outputs
This table maps each LangChain element in a guarded application to the NeMo Guardrails rail point that sees it, the team that should own the rule, and what to check in the release notes for the version you pin. Read it before deciding where each policy lives, because a rule placed on the wrong element can miss the content it was meant to catch.
| LangChain element | NeMo Guardrails rail point | Who owns the rule | Confirm in the release notes |
|---|---|---|---|
| User input | Input rails, with dialog rails for multi-turn flows | Security team writes policy; application team wires the chain | How user messages reach input rails, and whether structured message content is passed through unchanged |
| Chain input and output | Input rails before the chain, output rails after it | Platform team owns the wrapper; application team owns chain logic | How RunnableRails wraps chain inputs and outputs, and whether the output shape changes after wrapping |
| AI message | Output rails | Governance or security owner for response policy | Whether output rails see the full AI message, including content produced while streaming |
| Tool call arguments | Execution rails, checked before the tool runs | Security team sets the policy; tool owner defines allowed arguments | Whether tool call arguments are exposed to execution rails and in what format |
| Tool results | Execution rails on the return path, before the model reads the result | Tool owner and security team jointly | Whether tool results are passed to rails before the model sees them, and any known gaps |
| Memory or chat history | Input rails over history or dialog state | Application team designs memory; security owns retention rules | How chat history is supplied to rails, and whether earlier turns are re-checked on each request |
| Retrieved documents | Retrieval rails, when a retriever feeds the chain | Data owner for the corpus; security for filtering rules | The retrieval rail hook, the chunk format it receives, and how it is enabled for LangChain retrievers |
| Framework opt-in | Not a rail; enables the LangChain path with NEMOGUARDRAILS_LLM_FRAMEWORK=langchain | Platform engineering | That the environment variable still applies, and which LangChain package versions the release supports |
Security settings to decide in the NeMo Guardrails and LangChain integration
The LangChain integration puts guardrails in the path of model calls, tool execution and trace data, so each setting below decides what is blocked, what is stored and who can see it. Settings are easiest to get right when they are agreed in writing before the first agent runs in your environment.
Rails that run on tool calls
Decide which rails validate a tool call before execution and which validate the tool result before the model reads it. Input rails see the user message, but tool arguments built by the model can carry injected instructions, so the execution rails and tool rails need their own checks. For each tool, record what arguments are allowed, what data may leave through it, and whether a blocked call is retried, refused or escalated to a person. Test this with deliberately malicious tool arguments, not only with normal prompts.
NeMo Guardrails docsModel and API key injection
Model provider keys, the NVIDIA_API_KEY and any safety model endpoints should reach the container as runtime secrets from your secrets manager, not as values in config.yml or Colang files. Configuration files are usually copied between environments, committed to source control and attached to tickets, so a key stored there is exposed to everyone who reads them. Confirm how your container platform injects secrets, who can read them on the host, and how keys are rotated without rebuilding the image.
What LangSmith records and who reads it
LangSmith tracing can capture prompts, completions, tool inputs and outputs, and rail decisions, which often include user personal data. Decide which projects receive traces, whether content is masked before it leaves your environment, and how long traces are kept. Limit project access to the roles that review blocked calls, and confirm where the LangSmith data is hosted for your region and compliance scope. Check the vendor terms for retention and access before you enable tracing in production.
Scope and review of custom actions
Custom Python actions run with the permissions of the guardrails process, so each one can reach internal APIs, databases or files that the model itself cannot touch. Limit each action to the systems it needs, use dedicated service accounts, and review every action in code review before it is deployed. Keep a list of which agent or chain can call which action, and treat changes to that list as security-relevant changes.
Fail open or fail closed
Decide what happens when a rail errors, times out or cannot reach a safety model: the request is either blocked (fail closed) or passed through without the check (fail open). Fail closed protects sensitive workflows but can stop an agent for reasons unrelated to the attack, while fail open keeps the service running with a gap in coverage. Choose the behavior per rail and per tool, write it into the configuration review, and alert on every fallback so the gap is visible to operations.
Server and configuration access control
The guardrails server loads configurations from a folder and exposes an HTTP API, so anyone who can reach that API or write to that folder can change what the agent is allowed to do. Put the API behind authentication on your internal network, restrict who can deploy configuration changes, and keep configurations under version control with approval. Confirm which endpoints the LangChain application calls and block every other route at the network layer.
- Current release
- 0.25.0
How to test blocked and allowed calls before release
Before a NeMo Guardrails configuration reaches production in a LangChain application, the owning team should run a fixed test set against both the wrapped chain (with the rails attached through RunnableRails or the agent middleware) and the unwrapped chain (the same model, prompts and tools without rails). The comparison shows what the rails change: a prompt that the unwrapped chain answers but the wrapped chain blocks is a deliberate control, while a prompt that both chains handle badly points to a model or prompt problem that guardrails will not fix. Build the set in four groups: allowed prompts that represent normal business use, disallowed prompts that the policy must refuse, injection attempts that try to override instructions or pull data from tools, and tool calls with malformed or out-of-scope arguments. Each case should have a stated expected outcome, either allowed with a specific answer shape or blocked with a specific refusal or rail result.
Review each case in LangSmith traces, not only the final answer. Confirm which rail fired, whether the tool call was validated before execution, and whether the model saw a tool result it should not have received. Check that allowed cases were not blocked by an over-broad rail and that blocked cases did not reach the tool. Record for each case the test ID, the configuration version (the config.yml contents, Colang files, custom actions and the NeMo Guardrails and LangChain package versions), the expected and observed outcome, the trace link and the reviewer. Store these records alongside the configuration in version control so that a change to a rail, prompt or tool schema can be retested against the same cases and compared with the previous run. Confirm the LangSmith project, retention and access settings with your security team before traces containing prompts or customer data are retained.
Coverage targets, pass thresholds and the number of cases required in each group are set by the team that owns the application and the risk, not by this guide. Agree them in the written scope before testing starts, including who signs off a release, what happens to a failed case, and whether a retest is needed after a dependency upgrade. Ask the owning team to name the policy each disallowed case represents, because a test that cannot be traced to a requirement is hard to defend in a review. Any evidence intended for an external assessor should be reviewed against your compliance requirements first.
Common failures in the LangChain integration and how to fix them
This table lists the failures teams most often hit when wiring NeMo Guardrails into LangChain, with the cause and fix for each. Read it when a guarded application behaves as if no rails ran, or when the first attempt at a LangChain integration fails in testing.
| Failure | Cause | Fix |
|---|---|---|
| Rails silently do not run | The LangChain opt-in is not set, so the integration is never enabled in the process that serves the application. | Set NEMOGUARDRAILS_LLM_FRAMEWORK=langchain in the same environment as the application and container, then confirm at startup that the variable is present. |
| LangChain package or version mismatch | The installed LangChain packages do not match the NeMo Guardrails release, or a pinned version in an existing project conflicts with it. | Pin versions together in one lock file, check the NeMo Guardrails release notes and PyPI metadata for the release you run, and rebuild the image rather than patching it in place. |
| Python version outside the supported range | NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13, and the installer may fail or fall back to an older build on other versions. | Run the application and tests on a supported interpreter, set the interpreter in the container base image, and fail the build when the version check does not pass. |
| Tool rails do not trigger on agent tool calls | Tool calls are not routed through the rails, often because the agent is built with a direct model client or the tool call path bypasses RunnableRails. | Confirm the agent invokes the guarded runnable, not the raw model, and add a test that calls a known tool and checks for a rail trace before release. |
| Output rails alter streamed responses | Output rails need the complete response before they can judge it, so streamed tokens reach the client before the check finishes or are buffered unexpectedly. | Decide whether streaming or output checking takes priority for each route, and test streamed and non-streamed calls against the same blocked prompts before go-live. |
| Traces missing in LangSmith | Tracing is not enabled in the environment, the API key or project name is wrong, or the guarded calls run in a process that does not export traces. | Verify the LangSmith tracing variables and project name in the running process, send one test request, and confirm the run appears before relying on it for review. |
| Deprecated LLMRails used in code | Code still instantiates LLMRails, which NeMo Guardrails 0.25.0 deprecates in favor of Guardrails, with removal planned no earlier than 0.27.0. | Move to Guardrails using the 0.25 migration guide published by NVIDIA, update imports and tests, and treat deprecation warnings as failures in continuous integration. |
Questions teams ask before adding NeMo Guardrails to LangChain
How much effort does adding NeMo Guardrails to LangChain take?
Effort scales mainly with how many chains and tool-calling agents need rails, and how many distinct rail policies they need. A single chain behind one shared configuration is a small job. Each additional agent with its own tools, permissions and dialog flows adds configuration, testing and review work. Other drivers are whether the team already has Colang 1.0 or 2.0 configurations, how many custom actions call internal systems, and how much of the output is checked before it reaches a user. Ask for the effort estimate to be broken down per chain and per agent, so each line can be checked against the written scope.
Can our own team add NeMo Guardrails to LangChain without a partner?
Yes, if your team has Python engineers comfortable with LangChain, the NeMo Guardrails configuration format and the security review your organization requires. The library is open source under Apache 2.0, and the integration is opt-in through the NEMOGUARDRAILS_LLM_FRAMEWORK=langchain environment variable. The harder parts are usually policy design, testing rails against realistic attacks, and getting the evidence reviewed. A partner is useful when those steps need outside testing or when the team is short on time. Whichever path you choose, the scope should be written down before work starts.
What does the work need from our side?
Plan for four inputs. First, named application owners who can decide which topics, actions and responses are allowed for each chain or agent. Second, model access, including the main model and any safety models you plan to call, with credentials that the runtime can read from a secrets store. Third, LangSmith access, if you want traces of blocked and allowed calls reviewed by your team, with a decision on who can see prompt and response content. Fourth, test data: representative user inputs, tool calls, retrieved content and known attack prompts that the rails must handle. Missing test data is one of the most common reasons review takes longer than planned.
How does the LLMRails deprecation in 0.25 affect the build?
NeMo Guardrails 0.25.0 deprecates the LLMRails class in favor of Guardrails, with removal planned no earlier than 0.27.0, and NVIDIA publishes a 0.25 migration guide. For a new build, start with Guardrails so the code does not need rework later. For an existing LangChain integration built on LLMRails, the migration touches initialization code and any wrappers around RunnableRails, so it should be scoped and tested as its own task. Ask whether the migration is included in the quote or handled as a separate change, and confirm the exact deprecation behavior against the 0.25 migration guide before committing to a plan.
Do we need NVIDIA AI Enterprise to use NeMo Guardrails with LangChain?
This is a licensing question that the NeMo Guardrails buyer's guide answers in more depth, so read it before committing budget. The library itself is licensed under Apache 2.0 and is installed from PyPI. Whether any NVIDIA commercial product, hosted model or container is part of your design is a separate decision. Your architecture determines that: a LangChain integration that calls only models you already license may not need any NVIDIA commercial component, while a design that uses NVIDIA-hosted or NIM-based safety models has different terms. Confirm each component's license in writing before the design is approved.
What changes when a LangChain upgrade lands?
A LangChain upgrade can change the interfaces that RunnableRails wraps, the message and tool-call shapes that tool rails inspect, and the framework dependencies that NeMo Guardrails expects. Treat each upgrade as a regression event. Pin versions in your lock file, run the full set of chain and agent tests including blocked and allowed cases, and review traces in LangSmith to confirm that rails still fire on tool calls and tool results. Check the NeMo Guardrails release notes for the matching version, because the supported LangChain versions are tied to the library release. Ask the partner or your team to include upgrade testing in the support plan, since it recurs with every LangChain release you adopt.
Which checks should we run before a LangChain integration goes live?
Run tests that prove the rails block what they should and allow what they should. Cover each chain and agent with blocked inputs, blocked outputs, allowed requests and tool calls that must be stopped before execution. Confirm that tool results are validated before the model sees them, and that errors in rails fail closed rather than passing content through. Review LangSmith traces for a sample of blocked and allowed calls to check that the logged detail matches your data handling policy. Record the results so auditors and security reviewers can see what was tested and what failed. The test plan should be part of the written scope, not an afterthought.
How DeployOpen scopes and delivers the LangChain integration
DeployOpen plans and builds NeMo Guardrails inside LangChain applications in infrastructure you control, starting with a written scope that names the agents, chains and tools to be guarded. The work is delivered as a fixed-scope engagement with tested configurations, documentation and a handover your team can run.
How we scope
- Inventory which LangChain chains, agents and tools need guardrails, and which model endpoints they call.
- Confirm the Python version and LangChain packages your runtime supports before any build starts.
- Agree in writing which rails, tracing setup and test cases are in and out of scope.
How we build
- Set NEMOGUARDRAILS_LLM_FRAMEWORK=langchain in each runtime that uses the integration, then wrap chains with RunnableRails.
- Write config.yml, Colang files and any custom actions, and validate tool calls and tool results before the model sees them.
- Connect LangSmith or your approved tracing backend so blocked and allowed calls can be reviewed.
How we hand over
- Deliver the configuration repository, deployment files and a runbook covering rail changes and version upgrades.
- Document the test cases used for blocked and allowed calls, with the results recorded for your review.
- Walk your engineering and security teams through the trace review process and the open decisions left for them.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Plan NeMo Guardrails version upgrades with your team, including Colang and LangChain changes that need manual review.
- Confirm the current NeMo Guardrails release and its support status with NVIDIA before scoping a new upgrade.

