Skip to content

mozilla-ai/any-guardrail

Project logo

any-guardrail

Docs Linting Unit Tests Integration Tests

Python 3.11+ PyPI Discord

A single interface to use different guardrail models.

Motivation

LLM Guardrail and Judge models can be seen as a combination of an LLM + some classification function. This leads to some churn when one wants to experiment with guardrails to see which fits their use case or to compare guardrails. any-guardrail is built to provide a seamless interface to many guardrail models, both encoder (discriminative) and decoder (generative), to easily swap them out for downstream use cases and research.

Our Approach

any-guardrail is meant to provide the minimum amount of access necessary to implement the guardrails in your pipeline. We do this by providing taking care of the loading and instantiation of a model or pipeline in the backend, and providing a validate function to classify.

Some guardrails are extremely customizable and we allow for that customization as well. We recommend reading our docs to see how to build more customized use cases.

Quickstart

Requirements

  • Python 3.11 or newer

Installation

Install with pip:

pip install any-guardrail

Basic Usage

AnyGuardrail provides a seamless interface for interacting with the guardrail models. It allows you to see a list of all the supported guardrails, and to instantiate each supported guardrail. Here is a full example:

from any_guardrail import AnyGuardrail, GuardrailName, GuardrailOutput

guardrail = AnyGuardrail.create(GuardrailName.DEEPSET)

result: GuardrailOutput = guardrail.validate("All smiles from me!")

assert result.valid

Troubleshooting

Some of the models on HuggingFace require extra permissions to use. To do this, you'll need to create a HuggingFace profile and manually go through the permissions. Then, you'll need to download the HuggingFace Hub and login. One way to do this is:

pip install --upgrade huggingface_hub

hf auth login

More information can be found here: HuggingFace Hub

Contributing to any-guardrail

The guardrail space is ever growing. If there is a guardrail that you'd like us to support, please see our CONTRIBUTING.md for details.

About

Guardrails to support any-agent

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

Languages