
OpenAI Guardrails
https://github.com/openai/openai-guardrails-python- Category
- Developer Tools
- Rank
- No. 397Tools index
- Pricing
- Open Source
- Type
- TOOL
- Builder
- openai
- GitHub
- 245 stars
- Latest release
- v0.3.2
- Date
About
Official OpenAI Python library for adding input/output guardrails to LLM apps — block jailbreaks, PII leaks, and off-topic requests.
What it does
A configurable validation layer that wraps OpenAI clients and agent runs. You assemble checks into preflight, request, and response stages, then receive structured results or tripwire exceptions. Built-in checks cover moderation, URLs, personal data, hallucinations, jailbreaks, inappropriate text, topic boundaries, and custom prompts.
Why it's ranked here
The practical integration surface is the main draw. Existing OpenAI client code can adopt a compatible wrapper, while agent workflows get dedicated support. Configuration validation, staged execution, streaming checks, token accounting, and labeled-dataset evaluation make this more than a collection of filters. The preview status and fail-open default deserve caution.
What's good
It supports synchronous and asynchronous clients, Chat Completions, Responses, Agents SDK workflows, streaming, and optional Azure variants. Guardrail definitions carry typed configuration schemas and metadata, which helps validation and discovery. The evaluation framework compares models, measures latency, and produces ROC curves from JSONL datasets. PII masking can modify requests before generation.
Tradeoffs
The project labels itself preview. Some checks call paid OpenAI APIs, so protection adds cost and potentially latency. PII detection requires a separate spaCy model and fails configuration when that model cannot load. Third-party services such as Presidio carry separate terms. By default, guardrail execution errors are treated as safe and processing continues.
How to use it well
Best for Python teams already using OpenAI clients or the Agents SDK and willing to test policy behavior against labeled examples. Configure checks by pipeline stage, validate bundles before deployment, benchmark thresholds and models, then monitor tripwires and token use. It does not assume responsibility for legal compliance or safe retention of blocked content.
Technical notes+
pyproject.toml packages src/guardrails with Hatchling, requires Python 3.11 or newer, declares guardrails and guardrails-evals console scripts, and includes the Agents SDK and Presidio as core dependencies. src/guardrails/client.py subclasses synchronous and asynchronous OpenAI clients, while src/guardrails/agents.py attaches agent-level and tool-level checks. src/guardrails/runtime.py validates three-stage Pydantic bundles and normalizes synchronous checks into async execution. src/guardrails/_streaming.py checks accumulated output every 100 text chunks by default and performs a final check. src/guardrails/registry.py infers configuration and context schemas from type hints. Makefile defines linting, strict typing, tests, documentation builds, and a 95 percent coverage threshold for the main source package.
Observed
- License
- MIT
- Primary language
- Python
- Installation
- Published package installed with pip as openai-guardrails
- Interfaces
- Python library plus guardrails and guardrails-evals command-line entry points
- Python support
- Requires Python 3.11 or newer; classifiers list Python 3.11 through 3.14
- Platform support
- Declared operating-system independent
- Packaging
- Hatchling build backend with source code packaged from src/guardrails
- Integrations
- OpenAI synchronous and asynchronous clients, Agents SDK, and optional Azure client variants
Read from README.md, Makefile, pyproject.toml, src/guardrails/cli.py, src/guardrails/spec.py, src/guardrails/types.py, src/guardrails/agents.py, src/guardrails/client.py, src/guardrails/context.py, src/guardrails/runtime.py, src/guardrails/__init__.py, src/guardrails/registry.py, src/guardrails/_streaming.py, src/guardrails/exceptions.py, src/guardrails/_base_client.py.
What it can do
Block jailbreak attempts
User prompts/inputs to LLM → Filtered safe prompts or blocked malicious inputs
Detect and prevent PII leaks
LLM responses containing potential personal information → Sanitized responses with PII removed or blocked
Filter off-topic requests
User queries and prompts → Approved on-topic requests or rejection of irrelevant queries
Add input validation guardrails
Raw user inputs to LLM applications → Validated and approved inputs or rejection notices
Add output filtering guardrails
LLM-generated responses → Filtered safe responses or blocked harmful content
Integrate safety controls into Python LLM apps
Python LLM application code → Protected LLM application with embedded guardrails
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.