Skip to main content
The NeMo Guardrails server provides a REST API for adding guardrails to your LLM applications. It’s compatible with OpenAI’s Chat Completions API, making integration straightforward.

Starting the Server

Basic Usage

Start the server pointing to a directory containing guardrails configurations:
The server will:
  • Start on port 8000 by default
  • Load all valid configurations from subdirectories
  • Expose the Chat UI at http://localhost:8000
  • Expose the API at http://localhost:8000/v1/

Command Options

Available Options:
string
default:"./config"
Path to a directory containing multiple configuration sub-folders, or a single configuration directory.
integer
default:"8000"
The port that the server should listen on.
string
The default configuration to use when no config is specified in requests.
boolean
default:"false"
Enable verbose logging including prompts and completions.
boolean
default:"false"
Disable the web-based Chat UI.
boolean
default:"false"
Enable automatic reloading of configurations when files change.
string
default:""
A prefix to add to all server paths (must start with ’/’).

Configuration Directory Structure

Multiple Configurations

For multiple guardrails configurations:
Each subdirectory represents a separate configuration accessible via its name.

Single Configuration

For a single configuration:
When pointing to a directory with config.yml directly, the server runs in single-config mode.

API Endpoints

Chat Completions

The primary endpoint for generating responses with guardrails.
Request Body:
string
The ID of the guardrails configuration to use. Corresponds to the subdirectory name.
array
required
Array of message objects with role and content fields.
string
Optional model override. If specified, overrides the main model in the configuration.
boolean
default:"false"
Enable streaming responses.
integer
Maximum tokens to generate.
number
Sampling temperature (0-2).
number
Nucleus sampling parameter.
array
Stop sequences.
Response Format:

Streaming Responses

Enable streaming to receive responses token-by-token:

List Configurations

Get all available guardrails configurations:
Response:

List Models

Get available models from the configured provider:
Response:

Advanced Features

Context and State Management

Include context variables in your requests:

Thread Support

Maintain conversation threads across multiple requests:

Model Override

Override the configured model for specific requests:

Environment Variables

CORS Configuration

Enable Cross-Origin Resource Sharing:

Model Configuration

Set the main model engine and base URL:

Docker Deployment

Using Docker

Docker Compose

docker-compose.yml
Run with:

Chat UI

The built-in Chat UI is available at http://localhost:8000 when the server is running. Features:
  • Interactive chat interface
  • Configuration selection
  • Message history
  • Real-time streaming
Disable the UI:
When disabled, the root endpoint returns:

Health Checks and Monitoring

Health Check

Check if the server is running:
A successful response indicates the server is healthy.

Logging

Enable verbose logging to monitor requests:
Logs will include:
  • Request details
  • Configuration loading
  • LLM calls (if verbose)
  • Rail activations
  • Error traces

Integration Examples

OpenAI SDK

Use the OpenAI Python SDK with the guardrails server:

LangChain

Integrate with LangChain:

Production Deployment

For production deployments:
1

Use a process manager

Use systemd, supervisord, or PM2 to manage the server process.
2

Enable auto-reload

Use --auto-reload to automatically reload configurations without server restart.
3

Set up reverse proxy

Use Nginx or Apache as a reverse proxy for SSL/TLS termination and load balancing.
4

Configure CORS

Set appropriate CORS headers for your frontend applications.
5

Monitor logs

Set up log aggregation and monitoring with tools like ELK stack or Datadog.

Troubleshooting

Configuration Not Loading

Ensure your configuration directory has valid config.yml files:

Port Already in Use

Change the port:

Model Connection Issues

Verify environment variables:

Next Steps

Python API

Use guardrails programmatically in your code

CLI Tools

Interactive chat and testing tools

Configuration

Configure your guardrails

Docker Guide

Deploy with Docker