NeMo Guardrails with Hugging Face models and TGI

Connecting a Hugging Face model to NeMo Guardrails depends on how it is served. This page explains which engine to choose for TGI, OpenAI-compatible endpoints and in-process pipelines, and what to plan before you build.

On this page

Connecting Hugging Face models to NeMo Guardrails: which engine to use

A team that runs a Hugging Face model behind an HTTP endpoint and wants guardrails in front of it has one main decision: which NeMo Guardrails engine to configure. If the endpoint exposes /v1/chat/completions, the supported path is engine: openai with parameters.base_url pointing at the server and parameters.api_key set to the key the server expects. This path does not need LangChain. Servers that run unauthenticated still need a placeholder key value in the configuration, so confirm what your server requires before you write the file. The NeMo Guardrails supported LLMs documentation lists Text Generation Inference (TGI) under this pattern.

The huggingface_endpoint engine follows the LangChain path and uses the default text-generation schema, so it is a different integration with its own dependencies. The huggingface_pipeline, huggingface_hub, trt_llm and self_hosted engines run models in process or wrap LangChain classes with no native HTTP path. These engines require the LangChain opt-in, set with NEMOGUARDRAILS_LLM_FRAMEWORK=langchain. Choose them only when the model must run inside the guardrails process, and plan for the extra packages, memory and GPU capacity that places on the application container.

The serving stack itself is a planning decision, and it deserves a check before you commit. Hugging Face's TGI documentation and README state that text-generation-inference is in maintenance mode, that it accepts only minor bug fixes, documentation improvements and lightweight maintenance, and that Hugging Face now recommends downstream engines such as vLLM and SGLang. The TGI GitHub repository is archived and read-only, and its last release was v3.3.7 on December 19, 2025. TGI still works and carries an Apache 2.0 license, but a new deployment should weigh the lack of upstream fixes against its operating history. Confirm the engine you pick with your security team before the guardrail configuration is written, since changing servers later changes the base_url and the authentication setup.

What you need before connecting a Hugging Face endpoint

Connecting a Hugging Face model to NeMo Guardrails depends on four things: the Python runtime, the serving endpoint and its network path, the credentials the endpoint expects, and whether the LangChain opt-in is needed at all. Work through these before writing any configuration, because most connection failures trace back to one of them.

Python runtime version

NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13. Check the interpreter inside the same environment or container that will run the guardrails server, not only the one on a developer laptop. Pin the version in your image build so a base-image update does not silently change the runtime. If your platform team standardizes on a different Python release, confirm compatibility with the library before you build.

Supported Python
3.11 to 3.13
PyPI package page

Serving endpoint and network path

Decide where the TGI server runs and confirm the guardrails server can reach it over the network. The endpoint address is what goes into parameters.base_url for the openai engine, so a localhost address that works on a workstation will fail inside a container. Check DNS, firewall rules, service mesh policies and any proxy settings between the two services. Confirm the exact TGI image tag, model name and GPU hardware in your own environment, since these determine what the endpoint actually serves.

API key handling for the endpoint

Decide whether the endpoint requires authentication. If it does, store the key in your secrets manager and inject it into the guardrails server as an environment variable or mounted secret, not inside config.yml committed to source control. If the endpoint is unauthenticated, you still need a value for parameters.api_key where the chosen engine requires one, so confirm the placeholder behavior with the engine documentation before you rely on it. Rotate keys on the same schedule as your other model credentials.

Choosing the engine path

Endpoints that expose /v1/chat/completions, including TGI's Messages API, should use engine: openai with parameters.base_url and parameters.api_key. This path needs no LangChain opt-in. Only choose huggingface_endpoint, huggingface_pipeline, huggingface_hub, trt_llm or self_hosted when you have a specific reason to use the LangChain wrapper or an in-process model, because those engines are where the opt-in applies.

Supported LLMs docs

LangChain opt-in for in-process engines

Set NEMOGUARDRAILS_LLM_FRAMEWORK=langchain only when you use huggingface_endpoint or an in-process engine such as huggingface_pipeline. The opt-in is not needed for engine: openai against TGI. Install the LangChain-related packages that the chosen engine requires, and record the variable in your container definition so the setting survives redeploys. Confirm the packages against the supported LLMs page before building.

TGI maintenance status

The TGI repository is archived and read-only, and Hugging Face states that the project is in maintenance mode, with its last release published on December 19, 2025. Before you standardize on TGI, decide whether your platform team can accept an endpoint with no further feature development, or whether a successor engine such as vLLM or SGLang fits your plans. Record the TGI version you run and plan a review date.

TGI repository

How a Hugging Face model reaches NeMo Guardrails

The decision starts with the endpoint: if the serving layer exposes /v1/chat/completions, such as TGI's Messages API, configure engine: openai with parameters.base_url and parameters.api_key. Only in-process pipelines and huggingface_endpoint need the LangChain opt-in through NEMOGUARDRAILS_LLM_FRAMEWORK=langchain. Either way, the guardrails server or Python API sends traffic through input and output rails, and the boundary between the guardrails runtime and the model host is where you confirm authentication, network paths and what content is logged.

Engine choice and trust boundary between the guardrails host and the model host.

Configuring the OpenAI-compatible path step by step

This sequence connects a Hugging Face model server that exposes the OpenAI chat route to NeMo Guardrails, proves a direct call works, and then confirms that rails block a test prompt through the guardrails server. Each step ends with a check you can run before moving on.

  1. Confirm the chat route and model name

    Before editing any configuration, confirm that your TGI endpoint serves the Messages API at the chat completions route, typically under a /v1 base path, and note the exact model identifier the server reports. Send one request with curl or an HTTP client to the chat completions route from the machine that will run NeMo Guardrails, so network paths and TLS are proven first. Done is a well-formed JSON completion returned by the endpoint. If the route returns a 404, check the base path before changing anything else in the guardrails setup.

  2. Create the config.yml with the openai engine

    Create a configuration folder containing a config.yml file. Under the models section, set the model type to main, set engine to openai, set the model name to the identifier you confirmed, and set parameters.base_url to the endpoint base path. Set parameters.api_key from an environment variable rather than writing the secret into the file. If your TGI server is unauthenticated, confirm with the platform owner which placeholder value the client should send. Done is a configuration folder that loads without validation errors when the library reads it.

  3. Add the rails in Colang 1.0

    Add a Colang file that defines the input and output rails you need, such as a self-check input prompt or a blocked topic flow. Colang 1.0 is the default in NeMo Guardrails, so write the first version in that syntax and reference the flows from config.yml. Keep the rails minimal at this stage so any failure is easy to trace to one definition. Done is a configuration that loads with the rails registered, which you can confirm by listing the active rails in the loader output or logs.

  4. Test a direct call through the Python API

    Install the nemoguardrails package in a supported Python version (3.11, 3.12 or 3.13), then load the configuration folder in a short script and send one benign message through the Python API. Confirm that the response comes from your TGI model and that the rails did not block it. Then send a test prompt that your input rail should refuse and confirm it returns the configured refusal message. Done is one allowed completion and one blocked response, both visible in the script output or logs.

  5. Build and run the guardrails server

    Use the Dockerfile provided with NeMo Guardrails to build a server image, mount your configuration folder into the container, and pass the endpoint credentials as environment variables. Start the container and confirm from the startup logs that it found your configuration. Check that the container can reach the TGI endpoint over the network path your deployment uses. Done is a running server that reports a healthy status and loaded configuration.

  6. Send requests to the server and verify blocking

    Send a chat request to the guardrails server HTTP API, selecting your configuration as the server documentation describes, and confirm that a benign prompt returns a model completion. Then send the same blocked test prompt used in the Python check and confirm that the server returns the refusal. Compare the two results with the direct Python test to make sure behavior matches. Done is matching allowed and blocked results across the library and the server, which is the baseline for the next stage of testing.

When each engine is the right choice

This is the default choice when the model is already behind an HTTP server that accepts chat requests. Text Generation Inference (TGI) exposes a Messages API compatible with the OpenAI Chat Completions API, and NeMo Guardrails lists TGI among providers configured with engine: openai, parameters.base_url and parameters.api_key. The guardrails process calls the server over HTTP and never loads model weights, so the model server and the guardrails service can be scaled, patched and monitored separately.

  • No LangChain opt-in: The openai engine talks to the endpoint directly, so you do not need to set NEMOGUARDRAILS_LLM_FRAMEWORK=langchain for this path.
  • Existing serving stack: If TGI, vLLM or another compatible server already runs your models, this path reuses it without a second copy of the weights.
  • Separate failure domains: A model server outage shows up as an HTTP error you can alert on, not as a crash inside the guardrails process.
  • Auth on the wire: Set the API key for the server if it requires one, and confirm which routes your version exposes, since TGI is in maintenance mode and its successor servers may add or change routes.
  • Smaller guardrails image: The guardrails service carries no GPU runtime or model dependencies.

Before you commit, confirm that the endpoint answers /v1/chat/completions (or the TGI Messages route) with your model and that streaming behaves as your application expects.

Mapping config keys and model settings to the endpoint

This table maps each NeMo Guardrails configuration key to the matching setting on a TGI or OpenAI-compatible server. Read each row left to right, then confirm every value against your own deployment before you copy it into config.yml.

Config key or settingNeMo Guardrails sideTGI or serving sideWhat to confirm
Engine selectionengine: openai when the server exposes /v1/chat/completionsTGI Messages API, which is compatible with the OpenAI Chat Completions APIConfirm the route responds to chat requests on your TGI build before setting the engine
Base URLparameters.base_url set to the server root including the version pathHost and port where TGI listens, typically reached through your gatewayConfirm the path prefix your reverse proxy or ingress exposes, not only the container port
API keyparameters.api_key passed as the bearer credentialAuthorization header, only if your TGI or gateway enforces authenticationConfirm whether the endpoint checks keys; use a placeholder value if it does not
Model identifiermodel value in config.yml sent with each requestModel name the server reports for the loaded weightsConfirm the exact string returned by the server's model listing, since mismatches can fail requests
Huggingface_endpoint pathengine: huggingface_endpoint uses the LangChain path with the default text-generation schemaTGI text-generation route, not the chat routeConfirm the LangChain opt-in variable is set and the endpoint accepts the default request shape
LangChain opt-in variableNEMOGUARDRAILS_LLM_FRAMEWORK=langchain set in the runtime environmentNo serving-side setting; it changes how NeMo Guardrails calls the modelConfirm the variable reaches the container or process that runs the guardrails server
In-process pipeline engineshuggingface_pipeline and related engines load the model inside the guardrails processNo HTTP endpoint; model weights and GPUs sit with the guardrails processConfirm the host has the hardware and packages the pipeline needs before choosing this path
TGI version and release statusPinned library version of nemoguardrails in your buildTGI repository is archived and read-only; last release v3.3.7Confirm which TGI image you run and plan a successor engine such as vLLM or SGLang

Securing the guardrails-to-model connection

The guardrails server sits between your applications and the model host, so every request and response crosses a link you have to protect. The cards below cover the credentials, network paths, transport encryption, access rights and logging that connect NeMo Guardrails to a TGI endpoint or another OpenAI-compatible server, and each one names something your team can check.

Keep API keys out of config files

The engine: openai setup reads parameters.api_key from the configuration, so a key pasted into config.yml ends up in version control, container images and backups. Pass the key through an environment variable or your secrets manager and reference it at runtime. Check that the configuration folder in your repository holds no literal keys and that the container image does not bake one in. If your TGI endpoint runs without authentication, confirm that the placeholder value you use is not a real credential.

Restrict network paths to the model host

Allow the guardrails server to reach the TGI base_url on the required port and nothing else, and block direct access to that port from user networks. Enforce the rule with network policies, security groups or firewall rules, then test it from a host that should be blocked. Confirm which services can reach the guardrails server, since any caller that can reach it can use the model through it. Record the allowed flows in your architecture review so auditors can compare them with the live rules.

Encrypt the base URL with TLS

When the guardrails server and TGI run on different hosts, prompts and completions cross the network in the clear unless you terminate TLS. Put TLS in front of the TGI endpoint, use an https base URL in the configuration, and confirm that the guardrails server validates the certificate chain against your internal CA instead of disabling verification. Rotate certificates on a schedule and test expiry alerts. If TLS terminates at a load balancer, confirm the hop between it and TGI is also encrypted or limited to a private segment.

Limit who can change the server and configuration

The server image, the Python environment and the configuration folder with Colang files and custom actions together decide which rails run and which model receives traffic. Give the build pipeline write access to the image and read-only access to the configuration in production. Limit operators to deploying approved versions, and require review for changes to config.yml, custom actions and engine settings. Run the container as a non-root user and mount the configuration read-only where your platform allows it.

Log decisions without storing prompts

Logs from the guardrails server can capture full prompts and completions, which may contain personal data or confidential content. Decide what policy permits, such as recording the rail that fired, the outcome and a request identifier, and configure the server and any tracing exporter to omit message bodies unless the policy allows them. Set a retention period for the logs you do keep and check that the logs do not leave the environment you control. Test the setting with a sample request and read the output before go-live.

Why the serving stack choice affects long-term support

The serving engine behind a NeMo Guardrails deployment has a support life of its own, separate from the guardrails library. Text Generation Inference (TGI) is now in maintenance mode: Hugging Face says it will accept pull requests only for minor bug fixes, documentation improvements and lightweight maintenance. The huggingface/text-generation-inference repository is archived and read-only, and its last release, v3.3.7, was published on December 19, 2025. A team that picks TGI today is choosing an engine that will not receive new features, model support or most security-relevant changes from its upstream maintainer.

Hugging Face's own README now recommends downstream engines for new work, naming vLLM and SGLang, and local engines such as llama.cpp or MLX. Before committing, confirm the current status yourself on the TGI GitHub repository and the Text Generation Inference documentation, since the project's stated position can change. Ask your platform team who will own patching if a vulnerability is found in TGI, and whether your container image pipeline can rebuild it without upstream commits.

Plan an exit path to a supported engine from the start, even if TGI is the right choice for the first release. Because NeMo Guardrails reaches TGI through the engine: openai path with parameters.base_url and parameters.api_key, the guardrails configuration itself should stay largely unchanged when the model server is replaced, provided the replacement exposes the same chat API. Test that assumption with a staging swap, record the model and sampling settings that differ between engines, and keep guardrail regression tests in your pipeline so the move is verified rather than assumed.

Common failures when connecting Hugging Face endpoints

This table lists the failures teams most often hit when pointing NeMo Guardrails at TGI or other Hugging Face endpoints, with the likely cause and a concrete fix for each. Use it as a triage checklist, and confirm every fix against the guardrails server or application logs before closing the issue.

FailureLikely causeFix and how to verify
Connection errors or 404s on every callThe base_url in the engine: openai configuration omits the /v1 path segment that the OpenAI-compatible API expectsSet parameters.base_url to the full versioned path, then confirm in the logs that the request URL ends with /v1/chat/completions
404 on chat requests onlyThe endpoint serves a different route than the one the engine calls, or the configuration uses huggingface_endpoint against a chat-only routeConfirm the route the server exposes, use engine: openai for endpoints that serve /v1/chat/completions, and check the logged path matches it
401 or 403 responsesThe api_key is missing, misspelled in config.yml, or not exported to the container or process environmentPass the key through the configured environment variable, restart the server, and check the logs for the auth status returned by the endpoint
Unauthenticated server rejects placeholder keyThe endpoint runs without authentication but the configuration has no api_key value at allSet a non-empty placeholder value for the key so the client starts, and confirm the endpoint accepts the request in the logs
Huggingface_pipeline fails to load or is unrecognizedThe in-process engine is used without the LangChain opt-in, so the framework is not activeSet NEMOGUARDRAILS_LLM_FRAMEWORK=langchain in the environment, install the LangChain and Hugging Face packages, and recheck the startup log
Import or startup error on PythonThe runtime is outside Python 3.11, 3.12 or 3.13, which NeMo Guardrails 0.25.0 requiresRun the server under a supported interpreter in a fresh virtual environment, and confirm the interpreter version in the startup output
Streaming stops or arrives in a different shapeEndpoints differ in how they emit server-sent events and in chunk format, and some engines do not stream the same wayTest streaming against each endpoint separately, compare chunk output in the logs, and confirm the rails still run on the final text
Structured or JSON output fails validationGuided or structured output options differ between endpoints, so a schema accepted by one may be ignored or rejected by anotherSend the same structured request to each endpoint, compare the returned payloads, and add an output check before relying on the format

Questions teams ask before connecting Hugging Face models

Is NeMo Guardrails free to use under the Apache 2.0 license?

Yes, the NeMo Guardrails library is open source under the Apache License 2.0, so you can use, modify and deploy it without paying NVIDIA a license fee for the library itself. The license covers the code in the NVIDIA-NeMo/Guardrails repository. It does not cover the models you connect to it. Your Hugging Face model, its weights and any hosted endpoint carry their own license terms, and some safety or classifier models may have separate terms that you need to review. Your costs are the compute to run the guardrails server, the model endpoints you host or pay for, and the people who configure and test the rails. Confirm each model's license with your legal team before production use.

Is Text Generation Inference still a sound choice given its maintenance mode?

It depends on how much new work you expect from the serving layer. Hugging Face has placed text-generation-inference in maintenance mode, accepting only minor bug fixes, documentation and lightweight maintenance, and the GitHub repository is archived and read-only. Its last release was v3.3.7 on December 19, 2025. Hugging Face's own README now recommends downstream engines such as vLLM and SGLang, and local engines such as llama.cpp or MLX. Existing TGI deployments can keep working, but you should plan for a migration path, verify that your hardware and quantization needs are covered by the engine you pick, and keep NeMo Guardrails pointed at an OpenAI-compatible endpoint so that swapping the engine later is a configuration change. For new builds, compare engines before committing.

How much effort does the integration take, and what drives it?

Effort is driven by a few variables you can count before any work starts. The first is the number of model endpoints, since each application model, safety model and fact-checking model needs its own engine, base URL and credentials in the configuration. The second is the number and type of rails. Input and output moderation is simpler than dialog flows, retrieval rails or execution rails that validate tool calls. The third is the integration path. An endpoint that speaks the OpenAI chat API uses the engine: openai setting over HTTP, while in-process pipelines and the huggingface_endpoint engine go through the LangChain opt-in, which adds packages and container changes. The fourth is testing, including adversarial tests and regression runs after each configuration change. Ask any partner to break its estimate down by these four items.

What must our team provide before the work can start?

You need to provide several inputs, and most delays come from missing ones. Start with endpoint access: the base URLs, the authentication method and a test key for each model server, plus confirmation of which model and version each endpoint serves. Next, confirm model rights, meaning the license terms for each Hugging Face model and any safety model, and whether your use case is permitted. Network access is also needed, including routes from the guardrails server to the model servers, egress rules if any service is external, and a place to host the guardrails server, such as your cloud account, data center or air-gapped network. Finally, allocate staff time: an owner for the policy and the rails, a platform engineer for hosting, and reviewers who can judge blocked and allowed test cases. Ask the partner to list these inputs in the written scope.

Can an in-house team connect Hugging Face models to NeMo Guardrails on its own?

An in-house team with Python and container experience can connect an OpenAI-compatible endpoint, because the configuration is a config.yml file that sets the engine, parameters.base_url and parameters.api_key. The harder work is designing the rails and proving they hold. Colang 1.0 is the default and Colang 2.0 is also supported, so the team must choose one and stay with it. Teams that already run TGI or vLLM and have a test suite for prompts, blocked content and jailbreak attempts usually cover the basics quickly. Teams without that experience tend to struggle with rail design, evaluation and the security review that follows. A practical test is whether your staff can write and defend a set of adversarial test cases, and whether they can own the configuration after go-live.

How does an outside partner scope a NeMo Guardrails and Hugging Face engagement?

DeployOpen scopes work in writing before it starts, and most engagements are fixed-scope. A scope usually covers the endpoints in use, the engine path for each one, the rails to be built, where the guardrails server will run, the testing approach, and the handover of configuration and documentation. DeployOpen plans, implements, hardens, documents and supports self-hosted platforms inside your own infrastructure, so the models, guardrails server and logs stay where you control them. It also runs security testing, including AI and agent security reviews, but it does not issue audit reports or certifications. Ask any partner to show how each endpoint, rail and test case maps to a deliverable, and to state what you must provide. A quote follows from that written scope. Ongoing upgrades and testing can be handled under a retainer.

Should an endpoint use the openai engine or the huggingface_endpoint engine?

Use the openai engine when the endpoint exposes /v1/chat/completions, such as TGI's Messages API, because NeMo Guardrails documents that path for that case and it avoids the LangChain opt-in. Set parameters.base_url to the server address and parameters.api_key to the key the server expects. Use the huggingface_endpoint engine only when you need its LangChain path, which uses the default text-generation schema. The in-process options, including huggingface_pipeline, huggingface_hub, trt_llm and self_hosted, load models inside the application process and are LangChain wrappers without a native HTTP path, so they need the NEMOGUARDRAILS_LLM_FRAMEWORK=langchain setting. Confirm the engine list against the current supported LLMs page before you commit a design.

How DeployOpen scopes and delivers this integration

DeployOpen plans and implements NeMo Guardrails with Hugging Face models and TGI inside your own infrastructure, starting from a written scope that names the engine path, the endpoints and the rails. The work is delivered as a fixed-scope engagement with tests, documentation and a handover your team can run.

How we scope

  • Inventory which Hugging Face endpoints exist, whether each exposes the OpenAI-compatible chat route, and which runtime serves it
  • Decide between the openai engine path and the LangChain huggingface_endpoint or in-process pipeline path for each model
  • Agree in writing which rails apply to input, output and retrieval, and which safety models run alongside the application model
  • Confirm the TGI version and its maintenance status, since the project is in maintenance mode and archived

How we build

  • Write the config.yml, model parameters, base_url and api_key settings, and Colang files for each agreed rail
  • Stand up the guardrails server or Python integration on Python 3.11, 3.12 or 3.13 in your container or runtime
  • Test each engine path against the target endpoint, including streaming responses and the message validation the server applies
  • Run adversarial prompts and blocked-request checks to confirm each rail fires as the written scope requires

How we hand over

  • Deliver configuration files, version pins, container build files and a record of the engine choice for each model
  • Document the chosen path, its known limits and the steps a future model or endpoint change would require
  • Walk your platform and security engineers through configuration review, test results and the operational runbook
  • Record open items, such as manual review of any converted Colang, so ownership is clear at handover

How we support

  • Support after handover is available as a retainer, covering version upgrades and endpoint changes
  • Re-run the agreed test set when the TGI endpoint, NeMo Guardrails release or model changes
  • Plan replacement work with your team if the serving engine moves to a successor such as vLLM or SGLang
  • Confirm support terms, response expectations and included services in the written agreement before work starts

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.