Skip to main content
NeMo Guardrails supports multiple LLM providers including OpenAI, NVIDIA NIM, Google Vertex AI, and HuggingFace. Each provider requires specific configuration in your config.yml file.

Supported LLM Providers

OpenAI

GPT-3.5, GPT-4, and other OpenAI models

NVIDIA NIM

LLama, Nemotron, and NVIDIA optimized models

Vertex AI

Google’s Gemini and PaLM models

HuggingFace

Open-source models via pipeline or endpoints

OpenAI Configuration

Basic OpenAI Setup

From examples/bots/hello_world/config.yml:

OpenAI with Parameters

From examples/configs/sample/config.yml:

Supported OpenAI Models

string
  • gpt-4o - Latest GPT-4 Omni model
  • gpt-4o-mini - Smaller, faster GPT-4 Omni
  • gpt-4-turbo - GPT-4 Turbo
  • gpt-4 - GPT-4 base model
  • gpt-3.5-turbo - GPT-3.5 Turbo (chat)
  • gpt-3.5-turbo-instruct - GPT-3.5 Instruct (completion)

Environment Variables

Set your OpenAI API key:

NVIDIA NIM Configuration

Basic NIM Setup

From examples/configs/llm/nim/config.yml:

NIM with Cloud API

Multiple NIM Models

From examples/configs/content_safety/config.yml:

Environment Variables

For NVIDIA NIM cloud:

Google Vertex AI Configuration

From examples/configs/llm/vertexai/config.yml:

Vertex AI with Parameters

Supported Vertex AI Models

string
  • gemini-1.5-pro - Latest Gemini Pro
  • gemini-1.0-pro - Gemini Pro 1.0
  • gemini-1.5-flash - Fast Gemini model

Authentication

Vertex AI requires Google Cloud authentication:

HuggingFace Configuration

HuggingFace Pipeline

From examples/configs/llm/hf_pipeline_llama2/config.yml:

Other HuggingFace Pipeline Examples

From examples/configs/llm/hf_pipeline_vicuna/config.yml:

HuggingFace Endpoint

From examples/configs/llm/hf_endpoint/config.yml:

Environment Variables

Model Parameters

Common parameters across providers:
float
default:"0.7"
Controls randomness. Lower values make output more deterministic
integer
Maximum number of tokens to generate
float
default:"1.0"
Nucleus sampling parameter
float
default:"0.0"
Penalizes repeated tokens (OpenAI)
float
default:"0.0"
Penalizes tokens based on presence (OpenAI)
string
Custom API endpoint URL (NIM, custom deployments)
string
API key for authentication. Use environment variables for security

Multiple Model Types

You can configure different models for different purposes:

Streaming Support

Enable streaming for real-time responses. From examples/configs/streaming/config.yml:
Use streaming in Python:

Custom LLM Providers

You can add custom LLM providers by implementing the LLM interface:
Then use in config.yml:

Best Practices

1

Use Environment Variables

Never hardcode API keys in config files
2

Choose Appropriate Models

  • Use smaller models (e.g., gpt-4o-mini) for simple tasks
  • Use larger models (e.g., gpt-4o) for complex reasoning
  • Use specialized models for specific tasks (safety, embeddings)
3

Configure Timeouts

4

Test Locally First

Use local NIM deployments for development before switching to cloud APIs

Testing LLM Configuration

Troubleshooting

Ensure environment variables are set:
If empty, export them before running:
For NIM local deployments, verify the server is running:
Verify the model name matches the provider’s available models:

Next Steps

config.yml Schema

Learn about all configuration options

Guardrails Library

Explore built-in guardrails for different LLMs