Discover / LLM Ops & Observability
Guardrails
by guardrails-aiPython
Framework for adding structure, validation and correctness guarantees to LLM outputs.
Maturity: experimental because latest release v0.10.2 is pre 1.0. Derived from release and commit history, not a rating.
- Stars
- 7.2k
- Forks
- 665
- Downloads / mo
- 150k
- Last commit
- 2026-08-02
- License
- Apache-2.0
- Open issues
- 84
Market and trust evidence
Edition not yet matchedNo exact skills.sh identity match is available for this repository. Repository adoption and freshness remain visible above; install momentum is not inferred.
Trust analysis is a screening signal, not a security warranty. Read the ranking and trust methodology.
In practice
Written by AI from this repository’s README · high confidenceModel output can leak, offend or break schema, and there is no consistent layer to catch that before it ships.
Use it when
Use it when you need validators on prompts and responses, or want structured data generation with failure actions.
Not the right pick when
Each validator is a separate Hub package to install and configure, so the setup grows with the number of risks covered.
Capabilities
- input and output Guards around LLM calls
- validators installed from Guardrails Hub
- combine multiple validators in one Guard
- on_fail actions such as raising an exception
- structured data generation from LLMs
- guardrails configure CLI for Hub setup
Requirements
- guardrails configure to set up the Hub CLI
- individual validator packages installed from the Hub
Cost: Free and open source
Install
Derived from the published package name in the repository, not from a model.
Video walkthroughs
Guardrails for LLM Applications | Complete Tutorial for AI Developers WIth Guardrails AI
Advanced Guardrails for AI Agents | Full Tutorial
Third-party YouTube uploads matched to this tool by title, channel and repository name on 2026-08-03. Not made, reviewed or endorsed by SkillPilot. View counts and publish months are as of the match date and the month is approximate. Nothing loads from YouTube until you press play.
What the repository ships
Detected from the actual files in the repository root.
Latest release v0.10.2
Published 2026-06-04
What's Changed
- Create SECURITY_ADVISORY.md by @ShreyaR in https://github.com/guardrails-ai/guardrails/pull/1474
- Update SECURITY_ADVISORY.md by @ShreyaR in https://github.com/guardrails-ai/guardrails/pull/1478
- [Aikido] AI Fix for Template Injection in GitHub Workflows Action by @aikido-autofix[bot] in https://github.com/guardrails-ai/guardrails/pull/1467
- fix: update litellm version pin to allow >=1.83.0 by @vaibhatredu in https://github.com/guardrails-ai/guardrails/pull/1484
- Update SECURITY_ADVISORY.md by @ShreyaR in https://github.com/guardrails-ai/guardrails/pull/1490
- v0.10.2 by @CalebCourier in https://github.com/guardrails-ai/guardrails/pull/1486
- release workflow for trusted publishing by @zsimjee in https://github.com/guardrails-ai/guardrails/pull/1493
New Contributors
- @aikido-autofix[bot] made their first contribution in https://github.com/guardrails-ai/guardrails/pull/1467
- @vaibhatredu made their first contribution in https://github.com/guardrails-ai/guardrails/pull/1484
Full Changelog: https://github.com/guardrails-ai/guardrails/compare/v0.10.0...v0.10.2
Tags
README
<div align="center">
<img src="https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/Guardrails-ai-logo-for-dark-bg.svg#gh-dark-mode-only" alt="Guardrails AI Logo" width="600px">
<img src="https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/Guardrails-ai-logo-for-white-bg.svg#gh-light-mode-only" alt="Guardrails AI Logo" width="600px">
<hr>
</div>
News and Updates
- [Feb 12, 2025] We just launched Guardrails Index -- the first of its kind benchmark comparing the performance and latency of 24 guardrails across 6 most common categories! Check out the index at index.guardrailsai.com
What is Guardrails?
Guardrails is a Python framework that helps build reliable AI applications by performing two key functions:
- Guardrails runs Input/Output Guards in your application that detect, quantify and mitigate the presence of specific types of risks. To look at the full suite of risks, check out Guardrails Hub.
- Guardrails help you generate structured data from LLMs.
<div align="center">
<img src="https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/with_and_without_guardrails.svg" alt="Guardrails in your application" width="1500px">
</div>
Guardrails Hub
Guardrails Hub is a collection of pre-built measures of specific types of risks (called 'validators'). Multiple validators can be combined together into Input and Output Guards that intercept the inputs and outputs of LLMs. Visit Guardrails Hub to see the full list of validators and their documentation.
<div align="center">
<img src="https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/guardrails_hub.gif" alt="Guardrails Hub gif" width="600px">
</div>
Installation
pip install guardrails-ai
Getting Started
Create Input and Output Guards for LLM Validation
- Download and configure the Guardrails Hub CLI.
pip install guardrails-ai
guardrails configure
- Install a guardrail from Guardrails Hub.
pip install guardrails-ai-regex-match
- Create a Guard from the installed guardrail.
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)
Output:
Validation failed for field with errors: Result must match \(?\d{3}\)?-? *\d{3}-? *-?\d{4}
- Run multiple guardrails within a Guard.
First, install the necessary guardrails from Guardrails Hub.
pip install guardrails-ai-competitor-check guardrails-ai-toxic-language
Then, create a Guard from the installed guardrails.
from guardrails import Guard, OnFailAction
from guardrails_ai.competitor_check import CompetitorCheck
from guardrails_ai.toxic_language import ToxicLanguage
guard = Guard().use(
CompetitorCheck(["Apple", "Microsoft", "Google"], on_fail=OnFailAction.EXCEPTION),
ToxicLanguage(threshold=0.5, validation_method="sentence", on_fail=OnFailAction.EXCEPTION)
)
guard.validate(
"""An apple a day keeps a doctor away.
This is good advice for keeping your health."""
) # Both the guardrails pass
try:
guard.validate(
"""Shut the hell up! Apple just released a new iPhone."""
) # Both the guardrails fail
except Exception as e:
print(e)
Output:
Validation failed for field with errors: Found the following competitors: [['Apple']]. Please avoid naming those competitors next time, The following sentences in your response were found to be toxic:
- Shut the hell up!
Use Guardrails to generate structured data from LLMs
Let's go through an example where we ask an LLM to generate fake pet names. To do this, we'll create a Pydantic BaseModel that represents the structure of the output we want.
from pydantic import BaseModel, Field
class Pet(BaseModel):
pet_type: str = Field(description="Species of pet")
name: str = Field(description="a unique pet name")
Now, create a Guard from the Pet class. The Guard can be used to call the LLM in a manner so that the output is formatted to the Pet class. Under the hood, this is done by either of two methods:
- Function calling: For LLMs that support function calling, we generate structured data using the function call syntax.
- Prompt optimization: For LLMs that don't support function calling, we add the schema of the expected output to the prompt so that the LLM can generate structured data.
from guardrails import Guard
import openai
prompt = """
What kind of pet should I get and what should I name it?
${gr.complete_json_suffix_v2}
"""
guard = Guard.for_pydantic(output_class=Pet, prompt=prompt)
raw_output, validated_output, *rest = guard(
llm_api=openai.completions.create,
engine="gpt-3.5-turbo-instruct"
)
print(validated_output)
This prints:
{
"pet_type": "dog",
"name": "Buddy
}
Guardrails Server
Guardrails can be set up as a standalone service served by Flask with guardrails start, allowing you to interact with it via a REST API. This approach simplifies development and deployment of Guardrails-powered applications.
- Install:
pip install "guardrails-ai" - Configure:
guardrails configure - Create a config:
guardrails create --validators=hub://guardrails/two_words --guard-name=two-word-guard - Start the dev server:
guardrails start --config=./config.py - Interact with the dev server via the snippets below
# with the guardrails client
import guardrails as gr
gr.settings.use_server = True
guard = gr.Guard(name='two-word-guard')
guard.validate('this is more than two words')
# or with the openai sdk
import openai
openai.base_url = "http://localhost:8000/guards/two-word-guard/openai/v1/"
os.environ["OPENAI_API_KEY"] = "youropenaikey"
messages = [
{
"role": "user",
"content": "tell me about an apple with 3 words exactly",
},
]
completion = openai.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
)
For production deployments, we recommend using Docker with Gunicorn as the WSGI server for improved performance and scalability.
FAQ
I'm running into issues with Guardrails. Where can I get help?
You can reach out to us on Discord or Twitter.
Can I use Guardrails with any LLM?
Yes, Guardrails can be used with proprietary and open-source LLMs. Check out this guide on how to use Guardrails with any LLM.
Can I create my own validators?
Yes, you can create your own validators and contribute them to Guardrails Hub. Check out this guide on how to create your own validators.
Does Guardrails support other languages?
Guardrails can be used with Python and JavaScript. Check out the docs on how to use Guardrails from JavaScript. We are working on adding support for other languages. If you would like to contribute to Guardrails, please reach out to us on Discord or Twitter.
Contributing
We welcome contributions to Guardrails!
Get started by checking out Github issues and check out the Contributing Guide. Feel free to open an issue, or reach out if you would like to add to the project!