guardrails-ai
Adding guardrails to large language models.
What it is and what it does
Guardrails is a validation and safety framework for large language model applications. It provides two main capabilities: running configurable Input/Output Guards that detect and mitigate specific types of risks (using pre-built validators from Guardrails Hub), and generating structured data from LLMs by enforcing Pydantic schemas through either function calling or prompt optimization.
The framework works by composing multiple validators into Guards that intercept LLM inputs and outputs. It supports both direct Python usage and a standalone server mode (via Flask) that exposes a REST API. It integrates with popular LLM clients like OpenAI and supports custom validators. The dependency tree includes langchain-core, openai, litellm, pydantic, and observability tools (OpenTelemetry), making it suitable for production LLM pipelines.
Use it for:
- Validate LLM outputs against regex patterns, schema constraints, or custom business rules before returning to users.
- Detect and block toxic language, competitor mentions, or other harmful content in LLM responses.
- Generate structured JSON or Pydantic models from LLM outputs with guaranteed schema compliance.
- Run a standalone Guardrails service that multiple applications can call via REST API for centralized LLM validation.
- Combine multiple validators (e.g., toxic language + competitor detection) into a single Guard for multi-layer risk mitigation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Guardrails is a Python framework that validates and constrains LLM inputs and outputs by running configurable guards, and helps generate structured data from language models.
Yes. Guardrails addresses a real need in LLM applications—validating and constraining model outputs—with a mature, actively maintained framework. Low install friction, permissive licensing, and no known vulnerabilities make it a safe choice. Install if you need input/output validation, structured data extraction, or risk detection in LLM pipelines; the extensive dependency tree is justified by its integration with standard LLM tooling.
Install
guardrails-ai on PyPI
pip
pip install guardrails-aiuv
uv add guardrails-aipoetry
poetry add guardrails-aiInstalling guardrails-ai
Before you install
Low install friction with a pure-Python wheel. Active maintenance with a recent release. Depends on 27 runtime packages including langchain-core, openai, litellm, and pydantic, which are standard in LLM applications.
License in practice
Apache-2.0 permissive license allows commercial use, modification, and distribution with minimal restrictions.
Quickstart
pip install guardrails-ai
from guardrails import Guard, OnFailAction
from guardrails_ai.regex_match import RegexMatch
guard = Guard().use(
RegexMatch, regex="\\(?\\d{3}\\)?-? *\\d{3}-? *-?\\d{4}", on_fail=OnFailAction.EXCEPTION
)
guard.validate("123-456-7890")
Requires Python 3.10 or later. Additional guardrail validators must be installed separately from Guardrails Hub (e.g., guardrails-ai-regex-match).
Verify before relying
- Performance and latency characteristics of the 24 guardrails mentioned in the Guardrails Index benchmark.
- Whether the Guardrails Server (Flask-based) is production-ready or requires Docker/Gunicorn for all deployments.
- Compatibility and integration depth with specific LLM providers beyond those listed in dependencies.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (<3.14,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 27 — click, diff-match-patch, faker, guardrails-ai-types, guardrails-hub-types, jsonref, jsonschema, langchain-core, litellm, lxml, openai, opentelemetry-exporter-otlp-proto-grpc, opentelemetry-exporter-otlp-proto-http, opentelemetry-sdk, pip, pydantic, pydash, pyjwt, python-dateutil, requests, rich, rstr, semver, tenacity, tiktoken, typer, typing-extensions |
| Maintenance | actively maintained — 0 days since the last release |
| First released | |
| Downloads | 158,506/month — #10,722 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: guardrails_ai-0.11.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
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
guardrails-hub-typesProvides internal data structure definitions…
permissive · top 15,000 on PyPI
openai-guardrailsAdds configurable safety and compliance…
permissive · top 15,000 on PyPI
pydantic-ai-shieldsPydantic AI Shields provides guardrail…
permissive · top 15,000 on PyPI
llm-guardLLM Guard provides input and output scanning…
unclear · top 15,000 on PyPI
datarobot-moderationsEnforces content moderation on LLM prompts and…
unclear · top 15,000 on PyPI
toolguardGenerates deterministic Python code that…
permissive · top 15,000 on PyPI
nemoguardrailsAdds programmable guardrails to LLM-based…
permissive · top 15,000 on PyPI
openlitOpenLIT provides OpenTelemetry-native…
permissive · top 15,000 on PyPI