Install Custom Dependencies in NeMo Guardrails#
If you need to install additional packages in the NeMo Guardrails microservice to add more guardrail functionalities, you can extend the NeMo Guardrails image and use it in the Helm installation.
Create a
requirements.txt
file that lists the additional packages.Log in to the NGC Registry. For more information about using NGC Container Registry, refer to NGC Container Registry in the NGC Private Registry User Guide.
$ docker login nvcr.io
Pull the base NeMo Guardrails image.
$ docker pull nvcr.io/nvidia/nemo-microservices/guardrails:25.09
Create a Dockerfile that uses the NeMo Guardrails image as the base and installs the additional packages.
# The base image is distroless, but has a constraints.txt file that lists the dependencies. FROM nvcr.io/nvidia/nemo-microservices/guardrails:25.09 as base # The builder image is a Python image that can install additional packages. FROM python:3.11-slim as builder ENV VIRTUAL_ENV=/app/.venv ENV PATH="/app/.venv/bin:$PATH" WORKDIR /app # Copy the constraints.txt file from the base image. COPY --from=base /app/services/guardrails/constraints.txt /etc/constraints.txt # Copy the requirements.txt file from the build context. COPY requirements.txt /app/requirements.txt # Install operating system packages. If needed, add additional dependencies. RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ && rm -rf /var/lib/apt/lists/* # Create a virtual environment and install the additional dependencies. RUN python3 -m venv $VIRTUAL_ENV \ && pip install --upgrade pip \ && pip install --no-cache-dir -r requirements.txt -c /etc/constraints.txt # Create a final image using the original distroless image. FROM nvcr.io/nvidia/nemo-microservices/guardrails:25.09 as final WORKDIR /app/services/guardrails # Copy the application directory from the builder stage. COPY --from=builder /app/ /app/ # Copy the virtual environment from the builder stage. COPY --from=builder /app/.venv/lib/python3.11/site-packages/ /app/.venv/lib/python3.11/site-packages/
Build a new image.
$ docker build -t guardrails-with-additional-packages .
Push the Docker image to a registry of your choice.
If using NGC Container Registry, you can push the image with the following commands.
$ docker tag guardrails-with-additional-packages nvcr.io/nvidia/nemo-microservices/guardrails-with-additional-packages:latest $ docker push nvcr.io/nvidia/nemo-microservices/guardrails-with-additional-packages:latest
To pull the image from the registry during the NeMo Helm chart installation, you need to set up a secret using your NGC API key with the following key permissions: NGC Catalog, NGC Private Registry, and Public API Endpoints. If you need to create a new key, refer to Generating NGC API Keys in the NVIDIA NGC Catalog documentation.
$ export NGC_API_KEY="<your-ngc-api-key>"
$ kubectl create secret -n guardrails-ms \ docker-registry nvcrimagepullsecret \ --docker-server=nvcr.io \ --docker-username='$oauthtoken' \ --docker-password=$NGC_API_KEY
Make the following changes to the
values.yaml
file of the NeMo Microservices Helm Chart to use the image URI in your registry.guardrails: image: repository: nvcr.io/nvidia/nemo-microservices/guardrails-with-additional-packages tag: latest pullPolicy: Always
Install or upgrade the NeMo Guardrails microservice with the updated values file.
If you are installing the NeMo Guardrails microservice for the first time, use the following command.
$ helm install nemo-guardrails ./helm-chart \ --namespace guardrails-ms \ --set tags.platform=false \ --set tags.guardrails=true \ -f values.yaml
If you are upgrading the NeMo Guardrails microservice, use the following command.
$ helm upgrade nemo-guardrails ./helm-chart \ -f values.yaml