Guardrails AI

Security & Safety 💻 Python ⚖️ Apache-2.0 🟢 Actively maintained
7.4k stars

Guardrails is a Python framework for building reliable AI applications by adding Input/Output Guards that detect and mitigate risks in LLM interactions, and by generating structured data from LLMs. It is for developers who want to validate LLM inputs/outputs and enforce output schemas.

Guardrails AI demo
🎞️ Demo from the project README

✨ Key features

  • Input/Output Guards to detect and mitigate risks
  • Pre-built validators from Guardrails Hub
  • Structured data generation from LLMs
  • Supports function calling and prompt optimization
  • Can be used as a standalone server with REST API
  • Works with proprietary and open-source LLMs

🎯 Use cases

  • Validate LLM outputs for regex patterns
  • Check for toxic language or competitor mentions
  • Generate structured data like pet names with type and name
  • Deploy guardrails as a service for multiple applications

📦 Installation

🧰 Requirements: Python environment with pip; optional OpenAI API key for LLM calls.

pip install guardrails-ai

🚀 Usage

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")  # Guardrail passes

try:
    guard.validate("1234-789-0000")  # Guardrail fails
except Exception as e:
    print(e)

⚠️ Good to know

Guardrails validators are moving to standard PyPI packages and remote inferencing is being discontinued; users should migrate by August 25, 2026.

❓ FAQ

Can I use Guardrails with any LLM?

Yes, Guardrails can be used with proprietary and open-source LLMs.

Can I create my own validators?

Yes, you can create your own validators and contribute them to Guardrails Hub.

Does Guardrails support other languages?

Guardrails can be used with Python and JavaScript, with more languages planned.

Where can I get help with Guardrails?

You can reach out on Discord or Twitter.

📊 Repository

Stars★ 7,358
Forks🍴 688
Open issues🐛 83
Last commit🕒 Sep 4, 2026
Created📅 Jan 2023
Language💻 Python
License⚖️ Apache-2.0

🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.