Connecting a custom LLM backend to NeMo Guardrails: when a direct engine setting is not enough
Teams that route guardrailed traffic through an internal model gateway have three integration paths in NeMo Guardrails: the built-in engine: openai setting, a LangChain provider, or a custom LLMModel implementation. The right choice depends on two things: whether the gateway speaks an API shape the built-in engines already understand, and who will maintain the code that bridges the two. In config.yml, the models block names the engine, model and any connection parameters, and the library uses that entry for every rail that calls a model. If your gateway exposes an OpenAI-compatible endpoint, a direct engine setting with a custom base URL is usually the least code to own. Confirm that the gateway's routes, authentication headers and streaming behavior match what the client expects before you rely on that path.
LangChain integration is opt-in. Setting NEMOGUARDRAILS_LLM_FRAMEWORK=langchain in the environment tells the library to resolve model providers through LangChain instead of its native engines, so you should enable it only when a LangChain provider already covers your gateway and your team is willing to track LangChain versions alongside NeMo Guardrails. The current release is 0.25.0, published on 19 November 2026, and it requires Python 3.11, 3.12 or 3.13, so check your runtime image against that range before you compare options. Also confirm whether your chosen path works with the Colang version and server mode you run in production.
A custom LLMModel implementation gives full control over request shape, retries, authentication and token accounting, but the team then owns that code through every library upgrade and gateway change. Plan a test that sends the same prompts through the gateway directly and through the guardrailed configuration, and compares responses, error handling and timeouts. Ask the gateway team who issues credentials for the guardrails service, where those credentials are stored, and whether the gateway logs the calls that NeMo Guardrails makes, because those answers decide whether the integration can be audited later.
Which integration path fits your gateway
The most direct path is to declare the model in config.yml with the openai engine and point it at your gateway's base URL. NeMo Guardrails then sends requests in the OpenAI chat format, so this path fits gateways that already present an OpenAI-compatible API and teams whose main work is the guardrail configuration itself. The trade-off is that compatibility is assumed rather than negotiated. Differences in model naming, streaming behavior or error bodies appear at runtime, and your team has to work around them.
- Fit: gateways that already expose an OpenAI-compatible endpoint for chat completions.
- Requires: a model block in
config.ymlwith the engine and model name set, plus API credentials held in environment variables or your secrets store. - Effort: mostly configuration, followed by a test call for each model name the gateway serves.
- Trade-off: gateway quirks in authentication headers, retries or error formats surface during live use.
- Watch: how your gateway handles per-team keys and whether it returns errors in a shape the library can read.
Confirm the engine and base URL keys in the NeMo Guardrails documentation for your version before you commit to this path.
The LangChain path reuses an existing LangChain provider class to call the model. It is opt-in: NeMo Guardrails only uses LangChain when the environment variable NEMOGUARDRAILS_LLM_FRAMEWORK is set to langchain. This path fits teams that already wrap their gateway or model family in a LangChain provider and want to keep that wrapper. The trade-off is an extra dependency layer. Two libraries that both change over time now govern request handling, so behavior depends on the pairing of versions you run.
- Fit: teams that already have a LangChain provider for their gateway or model family.
- Requires: the environment variable set in the process or server, plus the LangChain provider package for your gateway.
- Version pinning: pin NeMo Guardrails and the LangChain packages together, then retest after each change to either one.
- Trade-off: retries, error mapping and response parsing come from the provider, so you control less of them.
- Runtime: NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13, so confirm the provider package supports the same interpreter.
Check which LangChain packages your release expects and whether your provider class is covered in the NeMo Guardrails documentation for that release.
A custom LLMModel implementation is Python code that sends requests from NeMo Guardrails to your internal gateway and maps the responses back. This path fits gateways with custom authentication, routing headers or response shapes that neither the OpenAI-compatible path nor a LangChain provider maps cleanly. It gives the most control over requests and errors. The cost is ownership: your team writes, tests and maintains the adapter, and each library release can change the interface it must implement.
- Fit: internal gateways with custom auth, per-request routing metadata or non-standard response formats.
- Requires: a Python class that implements the model interface for your NeMo Guardrails version, registered through initialization code in the configuration.
- Testing: unit tests against a stub gateway, followed by a live check through the same code path that production uses.
- Trade-off: full control over requests, timeouts and error handling, but the adapter needs retesting on every upgrade.
- Ownership: name the team that fixes the adapter when the gateway or the library changes.
Request the interface definition and registration steps for your version from the NeMo Guardrails documentation, and confirm them with a small proof of concept before you size the work.
Configuration options and when each fits
This table compares the three ways to connect a model to NeMo Guardrails: engine set to openai, a LangChain provider, and a custom LLMModel implementation for an internal gateway. Read each row as a question to answer for your own gateway, then confirm each capability in the NeMo Guardrails documentation for the release you run.
| Decision factor | engine: openai | LangChain provider | Custom LLMModel implementation |
|---|---|---|---|
| Configuration location | Model type and engine in config.yml, with an endpoint setting if supported | Provider and model in config.yml, with the LangChain framework enabled by environment variable | Python class registered in initialization code, referenced from config.yml |
| Dependencies | Core library and the OpenAI client package | Core library plus the LangChain integration package for the chosen provider | Core library plus whatever client code your gateway requires |
| OpenAI-compatible gateway fit | Usually the simplest path if the gateway accepts OpenAI-style requests; confirm the base URL setting | Fits gateways that a LangChain provider already supports; may need a custom base URL setting | Fits any gateway protocol, because you write the request and response handling |
| Custom authentication handling | Limited to the API key and headers the client supports; confirm how token refresh works | Depends on what the provider exposes; token refresh may need wrapper code | Full control over token acquisition, refresh and header injection in your code |
| Maintenance burden | Low, as long as the gateway keeps the OpenAI-style interface stable | Moderate, because provider and LangChain versions must be kept compatible | Highest, because your team owns the class through every library upgrade |
| Testing approach | Test with a stub endpoint and a few representative configurations | Test the provider integration and the framework switch in CI before each upgrade | Unit test the class directly and run end-to-end tests against the gateway in a staging environment |
| Best fit | Gateways that speak the OpenAI API and need little customization | Teams already using LangChain providers and wanting a supported integration path | Internal gateways with custom authentication or non-standard request formats |
How a guarded request reaches your internal gateway
The request starts in your application, which calls the NeMo Guardrails runtime rather than the model directly. Guardrails loads config.yml, Colang flows and any Python actions, then picks one of three LLM paths: the openai engine, a LangChain provider, or a custom LLMModel class that calls your internal gateway. The trust boundary sits around the gateway, so confirm where the gateway API key is stored, that the guardrails process can reach the gateway from its own network segment, and that no provider credentials are written into configuration files.
Request flow from application through Guardrails to the internal model gateway.
Setting up the backend connection step by step
This sequence takes a team from a pinned NeMo Guardrails install to a verified model connection, whether the model is reached through engine: openai, a LangChain provider or a custom LLMModel for an internal gateway. Each step ends with a check so the team knows the backend is reached and logged before moving on.
Pin the NeMo Guardrails version
Choose the exact release your team will run and pin it in your dependency file, for example the current 0.25.0 release published to PyPI under Apache-2.0. Pinning matters because configuration and Python API behavior changed across releases, so the version in the build must match the version in the test environment. Check: the installed package reports the pinned version in a clean virtual environment, and the same pin appears in the lock file that your CI pipeline uses.
Confirm the Python runtime
Verify that the runtime is Python 3.11, 3.12 or 3.13, the range listed for the 0.25.0 release. Run the interpreter version command inside the same image or host that will run the server, not only on a developer laptop. Check: the version command returns one of the supported minor versions, and the library imports without errors in that environment.
Choose the connection path
Decide among three paths: engine: openai for a provider whose API the built-in engine already supports, a LangChain provider enabled through the NEMOGUARDRAILS_LLM_FRAMEWORK=langchain environment variable, or a custom LLMModel for an internal model gateway. Record the reason for the choice, the gateway's API contract and who owns credentials for each path. Check: the team can state in one sentence which path it uses and why the other two were rejected, and the gateway owner has confirmed the API format in writing.
Write the model block in config.yml
Add a models entry to config.yml that names the model, the engine or provider and any connection parameters such as base URL and API key reference. Keep secrets in environment variables or your secrets manager rather than in the file itself. Check: loading the configuration with the Python API or the guardrails server reports the model as configured, and a missing key produces a clear error instead of a silent fallback.
Register a custom LLMModel when needed
If the path is an internal gateway with no built-in engine, write an initialization module that implements and registers a custom LLMModel class, then reference it from the configuration. This code runs at startup, so keep it small, version it with the configuration and review it with the platform team. Check: the module imports cleanly at startup, the registration appears in startup logs, and a direct test call returns a response in the expected shape.
Enable LangChain only when chosen
Set NEMOGUARDRAILS_LLM_FRAMEWORK=langchain only if the LangChain path was selected in the earlier step, since the integration is opt-in. Install the LangChain provider packages your team has approved and confirm them in the lock file. Check: the runtime reports LangChain as the active framework, and the environment variable is absent from deployments that use the other paths.
Verify with test prompts
Send a fixed set of test prompts through the Python API or the guardrails server, covering a normal request, a request that a rail should block and a request that exceeds expected length. Record the responses and the model identifier used for each. Check: every prompt returns the expected outcome, and responses come from the configured backend rather than a default model.
Confirm the request in gateway logs
Review the logs on the model gateway for each test prompt and confirm the request arrived with the expected model name, credentials and headers, and that no unexpected calls went to a provider. Keep this check with the test set so it runs after every configuration change. Check: each test prompt has a matching gateway log entry, and the team signs off that the backend path matches the design decision.
How the Guardrails object uses the model you configure
The rails in a NeMo Guardrails configuration do not call the model only when a user sends a prompt. Several rails call the configured LLM for their own tasks, such as self-check input and output moderation, intent generation for dialog rails, and bot message generation. That means the backend you connect is not used by one rail. It is used by every rail that depends on a model call, so a choice of provider, a gateway route or a custom LLMModel implementation changes the behavior, latency, logging and failure modes of the whole configuration. Before you choose a backend, list which rails in your config.yml make model calls, and confirm with a test run which of them fail if the backend returns an error or times out.
Initialization code is where the backend is wired in, and the version you target matters. NeMo Guardrails 0.25.0 deprecates the LLMRails class in favor of Guardrails, with removal planned no earlier than 0.27.0. Write any backend initialization code against Guardrails so it does not need to be rewritten within a few releases, and check each step against the NVIDIA 0.25 migration guide, which is linked from the NeMo Guardrails documentation. Confirm the exact import paths and constructor arguments in your pinned version, since examples in older blog posts and forum answers often use LLMRails.
Plan the upgrade path before the backend is in production. A custom gateway client that works on one release can break when the framework changes how it loads models or passes configuration, so pin the library version, keep the backend code in its own module with tests, and rerun your rail test suite after each upgrade. Ask your gateway team to confirm which model names, authentication headers and timeouts the rails will send, because those settings reach every rail at once.
How the backend choice changes security and operations
Whichever backend option you choose, it becomes part of the guardrail path, so it inherits the access, logging and failure risks of that path. The cards below cover the decisions that differ between engine: openai, a LangChain provider and a custom LLMModel gateway, and the checks to run before go-live.
Gateway credential handling
A custom LLMModel implementation usually holds a credential for the internal gateway, and that credential may be broader than a single application needs. Decide whether the guardrails service authenticates with a per-service key, a short-lived token or the identity of its host, and confirm the gateway can scope that credential to the models this configuration calls. Ask the gateway team how keys are rotated without restarting the guardrails service.
Where API keys live
Keys for engine: openai or a LangChain provider are normally read from environment variables, so they can appear in container specs, process listings or CI logs. Store them in your secrets manager and inject them at runtime, and confirm which configuration files in the project folder might be committed to version control. Check that no key is echoed in error traces when a provider call fails.
Logging prompts and responses at the gateway
Guardrails sit between users and models, so both the raw prompt and the model response may pass through your gateway logs and the guardrails logs at the same time. Agree which fields are recorded, how long they are kept and who can read them, and mask personal data before it reaches shared log stores. Confirm that the gateway's log settings match the retention rules your compliance team has approved.
Failure behavior when the gateway is down
If the gateway becomes unavailable, a custom backend can fail closed, blocking all traffic, or fail open, passing messages without the model-based checks. Neither option is free: fail-closed stops the assistant, and fail-open weakens the control. Decide the behavior per rail, test it with the gateway stopped, and confirm that the application shows users a clear message in each case.
Network path and trust boundaries
With engine: openai the guardrails service calls a provider endpoint directly, while a LangChain provider or custom backend may route through internal services. Map each hop, note which segments cross a trust boundary, and confirm that TLS is enforced on every connection. In air-gapped or segmented networks, verify that the gateway address is reachable only from the guardrails service and not from user-facing networks.
Upgrade regression testing of custom code
A custom LLMModel class depends on the NeMo Guardrails Python interfaces and on the gateway API, and both can change between releases. Pin the library version in your build, keep a regression suite that calls the backend with known prompts, and rerun it before each upgrade. Confirm the upgrade notes for the release you target, since interface changes in the custom code are the most likely source of breakage.
Questions buyers ask before connecting a custom backend
How much more effort is a custom LLMModel than engine openai?
A custom LLMModel takes noticeably more work than engine: openai, because your team or a partner writes and tests the connector code yourself. With the OpenAI engine, NeMo Guardrails already knows the request and response shape, so the work is mostly configuration. A custom backend adds a Python class that handles authentication, request formatting, response parsing, error handling, timeouts and token accounting for your gateway. Expect the extra effort to sit in testing edge cases, such as streaming, retries and malformed responses, rather than in the first successful call. Ask any partner to show how they will test each of those paths before the build starts.
Can our engineers connect a custom backend without outside help?
Yes, if you have Python engineers who can read the NeMo Guardrails configuration and the gateway's API documentation. The core task is small in concept but depends on details: how the gateway authenticates, how it reports errors, and how it returns usage data. Teams that have not built an LLM client before usually find the verification steps take longer than the code. An outside partner is most useful when the gateway is poorly documented, when security sign-off requires evidence you have not produced before, or when the same backend must work across several guardrail configurations and environments.
What do we need to provide before the work starts?
Plan to provide four things: the gateway's API documentation, a non-production account with representative permissions, a named technical owner who can answer questions about the gateway, and a security sign-off path. The documentation should cover authentication, request and response formats, model names, rate limits and error codes. Test accounts should reach the same gateway policies that production uses, so results carry over. Security sign-off should be agreed early, because it decides where credentials are stored, which network paths are allowed and what logging of prompts and responses is permitted.
How long does the connection work take for different gateways?
Duration depends mainly on how standard the gateway is. A gateway that exposes an OpenAI-compatible API may need only configuration and a short verification pass, while a proprietary gateway with custom authentication, streaming and per-team routing needs a full connector and test cycle. Your own environment also matters: network approvals, secrets handling and security review often take longer than the code. No timeline for this work is given here. Ask any partner for a duration tied to a written scope that lists the gateway features in use, the environments to cover and the tests that must pass.
What drives the cost of a custom backend connection?
Cost is driven by the number of gateway features your application uses, the number of environments, the security review load and the amount of testing required. Simple OpenAI-compatible connections cost less than gateways with custom authentication, streaming responses, token accounting or multiple model routes. One-time costs include design, connector development, test harnesses and the first security review. Recurring costs appear when the gateway changes, when NeMo Guardrails releases a new version or when new models are added. In a quote, ask for each item separately, the assumptions about the gateway and the cost of retesting after upgrades.
What should we check after the backend is connected?
Check that the guardrails still run when the gateway is slow, returns an error, or times out, because those failures are where custom connectors usually break. Confirm that prompts and responses are logged only where your policy allows, and that credentials are read from your secrets store rather than from configuration files. Run the same guardrail test set against the gateway and against a direct engine configuration, and compare results. Finally, record which NeMo Guardrails version the connector was tested with, since the library has changed between releases and upgrades need a fresh test pass.
A decision path for choosing the backend
Start with the interface your gateway already exposes. If the internal model gateway speaks an OpenAI-compatible API, the simplest route is to point NeMo Guardrails at it with the engine: openai model setting in config.yml and override the base URL to reach the gateway. Confirm with the gateway owner that it implements the chat completion endpoints the library calls, that it accepts the model names you will declare, and that it returns responses in the shape the client expects, including on streaming requests if you plan to use them. If any of these fail, the decision does not stop there, because the next questions still apply, but you should not assume compatibility from the product name alone.
If the gateway is not OpenAI-compatible, check whether a LangChain provider already fits. The LangChain integration is opt-in and is enabled by setting the NEMOGUARDRAILS_LLM_FRAMEWORK environment variable to langchain, so your platform team must approve that setting and the LangChain packages it pulls in as part of the same review. Ask whether an existing provider class can reach your gateway with configuration alone, and whether your security team has already approved that dependency chain. Adding a framework layer is a decision with its own upgrade and vulnerability-tracking cost, so it should be made deliberately rather than as a side effect of connecting one model.
Write a custom LLMModel implementation only when the gateway needs logic that configuration cannot express, such as per-request token exchange, tenant-based routing, or request signing that depends on runtime state. This is the most control and the most maintenance: your team owns the code, its tests and its behavior after each NeMo Guardrails upgrade. Before committing, also evaluate whether the NeMo Helix control plane fits your architecture. Its documentation describes running NeMo Guardrails as inference gateway middleware that applies guardrail configurations to model endpoints, which would move the guardrail layer out of your application code. That is a different architecture with different operators and dependencies, so confirm it against your requirements with the NVIDIA-NeMo/nemo-helix project before choosing it.
How DeployOpen scopes and delivers this integration
DeployOpen plans, implements and hands over a custom LLM backend connection for NeMo Guardrails inside your own infrastructure. We start from the backend choice your teams need, write the scope in advance, and leave your engineers with configuration, code, tests and runbooks they can maintain.
How we scope
- Confirm which model endpoints, gateways and providers the guardrails must reach, and where each runs.
- Decide between engine: openai, a LangChain provider or a custom LLMModel for your internal gateway, with the reasons written down.
- Agree the written scope, deliverables and timeline before any build work starts, as engagements are fixed-scope.
How we build
- Implement the chosen backend in config.yml and, where needed, a custom LLMModel class with its initialization code.
- Verify request and response handling, timeouts, authentication headers and error paths against your gateway.
- Test the configuration with representative prompts and confirm that rails still fire when the custom backend is active.
How we hand over
- Document the backend configuration, environment variables and the dependency versions the connection was built against.
- Walk your platform and security engineers through the code, the secrets handling and the rollback steps.
- Deliver a test set and runbook so your team can repeat the verification after each upgrade or gateway change.
How we support
- Offer ongoing support, upgrades and continuous testing for the connection as a retainer.
- Review the backend integration again when NeMo Guardrails changes its configuration or Python APIs between releases.
- Ask for a quote built from the written scope, including which parts are one-time work and which recur under a retainer.

