openai-guardrails
OpenAI Guardrails: A framework for building safe and reliable AI systems.
What it is and what it does
OpenAI Guardrails is a Python wrapper around OpenAI's client that intercepts and validates LLM requests and responses against configurable safety rules. It provides a drop-in replacement for the standard OpenAI client, letting you add guardrails without rewriting your application code. The package includes built-in checks for content moderation, PII detection, jailbreak attempts, hallucination detection, NSFW content, off-topic prompts, and URL filtering, all configured via JSON.
The package depends on openai, openai-agents, presidio-analyzer, pydantic, and thinc. It integrates with OpenAI's Agents SDK via GuardrailAgent for agent-based workflows and includes an evaluation framework to benchmark guardrail performance on labeled datasets. When a guardrail is triggered, it raises GuardrailTripwireTriggered, allowing you to handle violations gracefully. The spaCy model for PII detection is an optional but documented prerequisite if that guardrail is enabled.
Use it for:
- Protect customer-facing chatbots from jailbreak attempts and inappropriate content without modifying core chat logic.
- Detect and mask personally identifiable information in LLM inputs and outputs to meet data privacy compliance.
- Evaluate guardrail effectiveness on labeled datasets and benchmark different model configurations for safety performance.
- Integrate safety checks into OpenAI Agents SDK workflows to ensure agent outputs meet compliance requirements.
- Filter hallucinated or off-topic responses to keep LLM outputs within business scope and factual accuracy.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds configurable safety and compliance guardrails to LLM applications by wrapping OpenAI's Python client to automatically validate and moderate inputs and outputs against a wide range of built-in checks.
Yes, if you need to add safety and compliance checks to an OpenAI-based LLM application. The package is actively maintained, has low install friction, uses a permissive MIT license, and offers a drop-in integration pattern that minimizes code changes. It is still in preview (version 0.3.0), so expect potential API changes; verify stability for production use cases before committing to it.
Install
openai-guardrails on PyPI
pip
pip install openai-guardrailsuv
uv add openai-guardrailspoetry
poetry add openai-guardrailsInstalling openai-guardrails
Before you install
Low install friction with a pure-Python wheel. Active maintenance (last commit 2026-07-21, 24 days old). Requires Python 3.11 or later. The spaCy model for PII detection must be downloaded separately if that guardrail is enabled, which is documented as a prerequisite during client initialization.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial and open-source projects. No copyleft obligations.
Quickstart
pip install openai-guardrails
from pathlib import Path
from guardrails import GuardrailsOpenAI
client = GuardrailsOpenAI(config=Path("guardrail_config.json"))
chat = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": "Hello world"}],
)
print(chat.choices[0].message.content)
Requires Python 3.11+. If using the Contains PII guardrail, the spaCy model en_core_web_sm must be downloaded separately before client initialization.
Verify before relying
- Whether the package's evaluation framework (guardrail_evals) is production-ready or still in preview like the main package.
- Performance overhead of guardrail checks on typical LLM request latency.
- Whether custom guardrails beyond the built-in set can be easily defined by users.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — openai-agents, openai, presidio-analyzer, pydantic, thinc |
| Maintenance | actively maintained — 24 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 315,200/month — #7,689 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: openai_guardrails-0.3.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
guardrails-aiGuardrails is a Python framework that validates…
permissive · top 15,000 on PyPI
pydantic-ai-shieldsPydantic AI Shields provides guardrail…
permissive · top 15,000 on PyPI
nemoguardrailsAdds programmable guardrails to LLM-based…
permissive · top 15,000 on PyPI
guardrails-hub-typesProvides internal data structure definitions…
permissive · top 15,000 on PyPI
openai-agentsA framework for building multi-agent LLM…
permissive · top 1,000 on PyPI
codeshieldCodeShield filters code generated by LLMs to…
permissive · top 15,000 on PyPI
guardrails-ai-typesProvides type definitions and data structures…
permissive · top 15,000 on PyPI
llm-openai-pluginA plugin that extends LLM to access OpenAI…
permissive · top 15,000 on PyPI
openlitOpenLIT provides OpenTelemetry-native…
permissive · top 15,000 on PyPI
deepteamDeepTeam is an open-source red teaming…
permissive · top 15,000 on PyPI