Model or dataset
guardrails-ai/guardrails avatar
guardrails-ai/guardrails

Guardrails: A Python Framework for Validating LLM Inputs and Outputs

Adding guardrails to large language models.

7,610 stars741 forksPythonApache-2.0

At a glance

What is it?
Guardrails is a Python framework that wraps LLM calls with input/output validators and structured data generation. This review covers its mechanism, setup, limitations, and whether it fits your AI application.
Who is it for?
Adopt Guardrails if you need a programmable layer to enforce regex, toxicity, or competitor checks on LLM outputs and to coerce responses into Pydantic models. Skip it if your only need is one-off validation or if you require remote inference, which had a planned cutoff of August 25, 2026.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 5 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • guardrails-ai/guardrails7,610 ★ · +221
Star history
Repository2026-09-102026-11-15
guardrails-ai/guardrails7.4k7.6k

221 Stars in the last 66 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What Guardrails Solves and Who Needs It

Guardrails addresses a specific pain: LLM outputs are free-form and can contain unwanted content, such as toxic language or competitor names, and they rarely conform to a strict schema. The framework intercepts both inputs and outputs of LLM calls, applying validators that detect and mitigate risks. It also helps generate structured data from LLMs, turning raw text into typed objects. This is for developers building production AI features that must enforce business rules, such as banning competitor mentions or ensuring phone numbers match a pattern. It is less useful for exploratory prototyping where output shape is not a concern.

The Two Core Mechanisms: Guards and Validators

The README describes two key functions. First, Guardrails runs Input/Output Guards that detect, quantify, and mitigate specific risks. Validators are the individual measures, and multiple validators can be combined into a single Guard. Second, Guardrails generates structured data from LLMs. The framework does this either through function calling, for LLMs that support it, or through prompt optimization, where the expected schema is added to the prompt. The Guard object is central: you instantiate it, attach validators with the .use() method, and call .validate() on raw text. The OnFailAction.EXCEPTION option makes the guard raise an exception when validation fails, which forces the calling code to handle the error explicitly.

Installation and Getting Started

Installation is a standard pip command: pip install guardrails-ai. After that, you run guardrails configure to set up the Guardrails Hub CLI. Validators are installed as separate packages, for example pip install guardrails-ai-regex-match. The README shows a minimal example: import Guard and RegexMatch, create a guard with a regex pattern and OnFailAction.EXCEPTION, then call guard.validate("123-456-7890") to pass or guard.validate("1234-789-0000") to raise an exception. For multiple validators, you install packages like guardrails-ai-competitor-check and guardrails-ai-toxic-language, then attach both to the same guard. The framework also integrates with Pydantic: define a BaseModel, pass it to Guard.for_pydantic(output_class=Pet, prompt=prompt), and the guard returns raw and validated outputs.

Structured Data Generation: Function Calling and Prompt Optimization

The structured data feature is more than a wrapper. For LLMs that support function calling, Guardrails uses the function call syntax to elicit structured data. For others, it appends a schema suffix to the prompt, shown as ${gr.complete_json_suffix_v2} in the example prompt. This dual approach means the framework adapts to the model's capabilities. However, the quality of the structured output depends on the model's adherence to the schema, and the prompt optimization path may not be as reliable as function calling.

Limitations and the Remote Inferencing Shutdown

A significant limitation is the discontinuation of hosted remote inferencing. The README announces that validators are moving to standard PyPI packages and that remote inferencing had a planned cutoff of August 25, 2026, so code relying on Guardrails' hosted inferencing needs to migrate. The migration path is described in a GitHub issue, but it requires action. Another consideration: the framework is Python, so non-Python services would go through the Guardrails Server REST API. Additionally, the regex example shows that validation is strict; a slight deviation like '1234-789-0000' fails, which may be too rigid for natural language inputs unless you design regexes carefully. Each validator adds work to every call; the Guardrails Index the README links benchmarks the performance and latency of 24 guardrails.

Maintenance, Licensing, and Upgrade Cost

Guardrails is Apache-2.0 licensed, which permits commercial use with attribution and no copyleft restrictions. The repository is active, with recent releases in 2026 and a default branch of main. The maintenance cost is moderate: you must track the migration of validators to separate pip packages, as the current hub-based installation may change. Upgrade cost is not zero because the discontinuation of remote inferencing may require rewriting parts of your integration. The README shows a clear migration issue link, but no detailed changelog is provided, so you should review release notes for breaking changes when upgrading from v0.10.x to v0.11.0.

Alternative: Direct Validation Libraries and Structured Output Tools

An alternative is to use a dedicated validation library like Pydantic for schema enforcement combined with a content moderation API for toxicity checks. The difference in approach is that Guardrails unifies these concerns into a single Guard object, whereas the alternative requires you to write separate code for each validation step. For example, you could use Pydantic to parse LLM output into a Pet model, but you would need to handle parsing errors yourself. For toxicity, you might call a moderation endpoint separately. Guardrails abstracts that orchestration, but it introduces its own API and dependency on the Guardrails Hub. If you prefer minimal dependencies and full control, the alternative may be simpler, but it lacks the pre-built validators and the combined input/output interception.

Editorial conclusion

Adopt Guardrails if you need a programmable layer to enforce regex, toxicity, or competitor checks on LLM outputs and to coerce responses into Pydantic models. Skip it if your only need is one-off validation or if you require remote inference, which had a planned cutoff of August 25, 2026. Before committing, verify that the validators you need are available as standalone PyPI packages and whether your LLM provider supports function calling, which Guardrails uses for structured data when available and otherwise falls back to adding the schema to the prompt. The framework is Apache-2.0 licensed and actively maintained, but its future depends on the migration to standard pip packages, so confirm the migration path for any validators you plan to use.

Frequently asked questions

What is guardrail in AI?

In this project a guardrail is a validator. Guardrails Hub is a collection of pre-built measures of specific types of risk, and multiple validators can be combined into Input and Output Guards that intercept the inputs and outputs of LLMs. The framework does two things overall: it runs those guards to detect, quantify and mitigate risk, and it helps you generate structured data from LLMs.

how to install guardrails ai

Run pip install guardrails-ai and then guardrails configure. Each validator is a separate package installed with pip, for example guardrails-ai-regex-match, guardrails-ai-competitor-check or guardrails-ai-toxic-language. The distribution is guardrails-ai while the import is guardrails, and the project declares support for Python 3.10 up to but not including 3.14.

how to use guardrails in llm

Build a Guard from installed validators with Guard().use(...), pass on_fail=OnFailAction.EXCEPTION, and call guard.validate() on the text; multiple failing validators are reported together in one message. For structured output, define a Pydantic BaseModel and call Guard.for_pydantic(output_class=..., prompt=...), which uses function calling where the model supports it and otherwise appends the output schema to the prompt.

how to use guardrails ai

Beyond in-process validation there is a server mode run with guardrails start, served by Flask over a REST API, configured with guardrails create --validators=hub://guardrails/two_words --guard-name=two-word-guard and started with guardrails start --config=./config.py. Clients either set gr.settings.use_server = True with gr.Guard(name='two-word-guard'), or point openai.base_url at the guard's endpoint. The docs recommend Docker with Gunicorn for production.

Official sources

  1. guardrails-ai/guardrails on GitHub
  2. License: Apache-2.0
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/guardrails-ai-guardrails.svg)](https://hysenlabs.com/projects/guardrails-ai-guardrails)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/guardrails-ai-guardrails.svg)](https://hysenlabs.com/projects/guardrails-ai-guardrails)

Was this useful?