Guardrails AI Integration
Connect Guardrails AI to LLM API for AI-powered capabilities
Guardrails AI is an open-source framework for adding validation and safety checks to LLM outputs. It provides validators for content safety, format compliance, factual accuracy, and more.
Guardrails AI wraps LLM calls, so configuring the underlying provider to use LLM API adds safety to all responses.
Prerequisites
- An LLM API account with an API key
- Guardrails AI installed or accessible
Setup
Get Your LLM API Key
- Log in to your LLM API dashboard
- Click Create Key to Start
- Copy your new API key immediately — it will only be shown once
- Store the key securely (e.g., in a password manager or
.envfile)
LLM API is an OpenAI-compatible gateway that gives you access to dozens of AI models through a single API key and endpoint.
Use LLM API with Guardrails AI
- Install Guardrails:
pip install guardrails-ai- Configure with LLM API:
import guardrails as gd
from guardrails import Guard
import openai
openai.api_key = "your-llm-api-key-here"
openai.base_url = "https://api.llmapi.ai/v1"
guard = Guard.from_rail("my_guard.rail")
result = guard(
model="openai/gpt-4o",
messages=[{"role":"user","content":"Hello"}]
)- Guardrails will validate all LLM API responses.
Test the Integration
Verify that Guardrails AI can successfully communicate with LLM API by sending a test request. All requests will now be routed through LLM API.
Guardrails AI adds output validation on top of LLM API for production-safe AI applications.
Benefits of Using LLM API with Guardrails AI
- Multi-Provider Access: Use models from OpenAI, Anthropic, Google, and more through a single API
- Cost Control: Track and limit your AI spending with detailed usage analytics
- Unified Billing: One account for all providers instead of managing multiple API keys
- Caching: Reduce costs with response caching for repeated requests
View all available models on the models page.
How is this guide?