List Guardrail Configurations

View as Markdown

Use the /v1/rails/configs endpoint to retrieve the list of available guardrails configurations from the server.

Request

$curl http://localhost:8000/v1/rails/configs

Response

The endpoint returns an array of configuration objects, each with an id field:

1[
2 {"id": "content_safety"},
3 {"id": "jailbreak_detection"},
4 {"id": "topic_safety"}
5]

Using Python

1import requests
2
3base_url = "http://localhost:8000"
4
5response = requests.get(f"{base_url}/v1/rails/configs")
6configs = response.json()
7
8print("Available configurations:")
9for config in configs:
10 print(f" - {config['id']}")

Example output:

Available configurations:
- content_safety
- jailbreak_detection
- topic_safety

Use a Configuration

After retrieving the available configurations, use a configuration ID in your chat requests:

1# Get available configs
2response = requests.get(f"{base_url}/v1/rails/configs")
3configs = response.json()
4
5# Use the first available config
6if configs:
7 config_id = configs[0]["id"]
8
9 response = requests.post(f"{base_url}/v1/chat/completions", json={
10 "model": "meta/llama-3.1-8b-instruct",
11 "messages": [{"role": "user", "content": "Hello!"}],
12 "guardrails": {
13 "config_id": config_id
14 }
15 })
16 print(response.json())

How Configurations Are Discovered

The server discovers configurations based on how it was started:

Multi-config mode (default): The server scans the configuration directory for sub-folders containing a config.yml or config.yaml file. Each sub-folder becomes an available configuration with its folder name as the ID.

examples/configs/
├── content_safety/ → config_id: "content_safety"
│ └── config.yml
├── jailbreak_detection/ → config_id: "jailbreak_detection"
│ └── config.yml
└── topic_safety/ → config_id: "topic_safety"
└── config.yml

Single-config mode: If the server is pointed to a folder containing a config.yml file directly (not in sub-folders), only that configuration is available. The folder name becomes the configuration ID.

$nemoguardrails server --config examples/configs/content_safety

The endpoint returns:

1[{"id": "content_safety"}]