OpenAI Guardrails: A framework for building safe and reliable AI systems.
Actively maintained. Last release 5 weeks ago, commits in 11 of the last 26 weeks. A safe choice.
pip install openai-guardrailsOpenAI Guardrails: Python (Preview)
Add configurable safety and compliance checks to LLM applications. OpenAI Guardrails wraps the OpenAI Python client to validate inputs and outputs, and integrates with the OpenAI Agents SDK.
Configure guardrails · Documentation · Examples
Installation
Requires Python 3.11+. Install openai-guardrails:
pip install openai-guardrails
If your configuration uses Contains PII, also install its spaCy model during build or deployment:
python -m spacy download en_core_web_sm
For uv with spaCy 3.8, install the model wheel directly:
uv pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl
Contains PII validates and loads this model during client initialization; a missing or unloadable model fails configuration before any request. See the Contains PII guide for configuration options.
Quickstart
- Create and export a pipeline configuration with the Guardrails wizard. Save it as
guardrails_config.jsonin your working directory. - Set the
OPENAI_API_KEYenvironment variable to your OpenAI API key. - Use
GuardrailsOpenAIin place ofOpenAI:
from pathlib import Path
from guardrails import GuardrailsOpenAI, GuardrailTripwireTriggered
client = GuardrailsOpenAI(config=Path("guardrails_config.json"))
try:
# Chat Completions API
chat = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "Hello world"}],
)
print(chat.choices[0].message.content)
# Responses API
response = client.responses.create(
model="gpt-5",
input="What are the main features of your premium plan?",
)
print(response.output_text)
except GuardrailTripwireTriggered:
print("Message blocked by guardrails.")
