guardrails-ai

guardrails: Validate LLM Inputs and Outputs

Guardrails is a Python framework for checking LLM inputs and outputs against configurable validators and for generating structured data. It suits teams building AI applications that need validation and error handling around model responses.

PythonApache-2.0AILLMFramework
Stars
7.5k
Forks
711
Stars, last 8 days
+29

Our take

Health score

58/100

How it is scored
Activity
65
Community
80
Issues
51
Pull requests
36

+29 stars in the last 8 days

  • Slower to merge pull requests than 86% of the projects we track

Overview

Guardrails is a Python framework for adding validation around language model applications. It lets developers apply one or more validators to inputs and outputs, then define how the application should handle validation failures. Validators can be installed from Guardrails Hub or created by developers.

The framework also helps produce structured output from LLMs using a schema such as a Pydantic model. It is useful when an application needs more control over content risks or response formats than a model prompt alone provides.

Key Features

  • Validate LLM inputs and outputs with configurable guards.
  • Combine validators, including validators installed from Guardrails Hub.
  • Choose failure handling behavior for validation errors.
  • Generate structured data from LLMs using Pydantic models.
  • Use function calling or prompt-based schema guidance, depending on model support.
  • Run guards through a standalone Flask service and REST API.
  • Connect to proprietary and open-source LLMs.

Use Cases

  • AI application developers can reject or handle responses that fail content or format checks before showing them to users.
  • Teams processing user prompts can screen inputs for specific risks before sending them to a model.
  • Developers building extraction or generation workflows can validate that responses conform to a Pydantic data model.
  • Platform teams can expose configured guards as a REST service for applications that need a shared validation layer.

Getting Started

Install the Python package:

pip install guardrails-ai

See the README and documentation for configuration and usage details.

Considerations

Guardrails adds validation behavior that you must configure for your application. The available validators and their installation requirements may vary. The README also announces that hosted remote inferencing is being discontinued, so check the migration guidance before relying on that service. The repository describes Python and JavaScript usage, but this repository is implemented in Python.

Found this useful?

Share it with someone who would like guardrails.