whatisgithub

What is guardrails?

guardrails-ai/guardrails — explained in plain English

Analysis updated 2026-06-24

6,857PythonAudience · developerComplexity · 3/5LicenseSetup · easy

In one sentence

A Python library that sits between your app and an AI language model to validate outputs for safety and format, and to enforce structured data shapes instead of free-form text responses.

Mindmap

mindmap
  root((Guardrails))
    What it does
      Output validation
      Structured output
      Safety checks
    Key concepts
      Guard object
      Validators
      Guardrails Hub
    Integration
      Standalone server
      OpenAI-compatible API
      pip install
    Use cases
      Toxicity filtering
      Format enforcement
      PII detection
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add a toxicity or competitor-mention check to a chatbot so flagged responses trigger an error before reaching users.

USE CASE 2

Force an AI model to return a structured Python object with specific fields instead of free-form text.

USE CASE 3

Run Guardrails as a standalone server so multiple services share one validation layer through a standard web API.

USE CASE 4

Browse Guardrails Hub to install pre-built validators for phone number format, PII detection, or hallucination checks.

What is it built with?

Python

How does it compare?

guardrails-ai/guardrailspallets/werkzeugclovaai/donut
Stars6,8576,8606,864
LanguagePythonPythonPython
Setup difficultyeasyeasyhard
Complexity3/53/54/5
Audiencedeveloperdeveloperresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min
Use freely in any project, including commercial ones, as long as you include the Apache 2.0 license notice.

So what is it?

Guardrails is a Python library for adding safety and structure checks to applications that use AI language models. When you build something on top of a large language model, the model's output is not guaranteed to be safe, accurate, or formatted in any particular way. Guardrails sits in the middle and checks what goes in and what comes out, raising an error or taking another action when something looks wrong. The library has two main uses. The first is validation: you define rules that the model's output must pass, such as checking for toxic language, detecting whether the model mentions a competitor's name, or confirming that a phone number matches the right format. These rules are called validators and can be combined into a "Guard" object that checks each response. Guardrails Hub is an accompanying catalog where you can browse and install pre-built validators for dozens of common scenarios. The second use is structured output: instead of getting back a block of plain text from the model, you tell Guardrails the exact data shape you want (using Python data classes), and it prompts the model to produce output that fits that structure. For models that support it, this works through a function-calling mechanism. For models that do not, Guardrails adjusts the prompt to describe the expected format. Guardrails can also run as a standalone server using a built-in command. Once running, other parts of your application can talk to it over a standard web API, including using the same client library that the OpenAI SDK uses. This makes it possible to add Guardrails to an existing project without changing much of the surrounding code. The project is open source under the Apache 2.0 license and installable via pip. A hosted documentation site, a Discord community, and a benchmark index comparing validator performance across common risk categories are available at guardrailsai.com.

Copy-paste prompts

Prompt 1
I am building a chatbot and want to block any response that mentions a competitor name. How do I set that up with Guardrails?
Prompt 2
How do I use Guardrails to make a language model always return a Python object with specific fields like name, email, and age?
Prompt 3
Show me how to run the Guardrails server and call it from my app using the OpenAI-compatible client library.
Prompt 4
How do I install a pre-built validator from Guardrails Hub and combine it with a custom validator in a single Guard object?

Frequently asked questions

What is guardrails?

A Python library that sits between your app and an AI language model to validate outputs for safety and format, and to enforce structured data shapes instead of free-form text responses.

What language is guardrails written in?

Mainly Python. The stack also includes Python.

What license does guardrails use?

Use freely in any project, including commercial ones, as long as you include the Apache 2.0 license notice.

How hard is guardrails to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is guardrails for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.