skillfed

openai-guardrails

OpenAI Guardrails: A framework for building safe and reliable AI systems.

openai-guardrails v0.3.0 315.2K downloads/30d#7,689 on PyPI229
Permissive license MIT Active released

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-guardrails

uv

uv add openai-guardrails

poetry

poetry add openai-guardrails

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

llm safety guardrailsopenai content moderationpii detection pythonjailbreak detectionllm input output validationai compliance frameworkhallucination detection
llm-safetycontent-moderationcompliance

More Python Modules packages

Further reading