Skip to main content

No project description provided

Project description

Project logo

any-guardrail

Docs Linting Unit Tests Integration Tests

Python 3.11+ PyPI Discord

A single interface to use different guardrail models.

any-guardrail provides a unified interface for AI safety guardrails, for example, letting you detect toxic content, jailbreak attempts, and other risks in LLM inputs and outputs. Switch between different guardrail providers, both encoder-based (discriminative) and decoder-based (generative) models like Llama Guard and ShieldGemma, without changing your code.

Some guardrails are extremely customizable, which any-guardrail fully exposes. See the complete list of supported providers and customization examples in our docs.

Why any-guardrail?

  • Unified API: Switch between evergrowing list of guardrail providers
  • Production-ready: Built for real-world LLM applications
  • Flexible: Use encoder-based (fast) or decoder-based (customizable) models

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

# Initialize guardrail
guardrail = AnyGuardrail.create(GuardrailName.DEEPSET)

# Validate input before sending to your LLM
result: GuardrailOutput = guardrail.validate("How do I hack into a system?")

if not result.valid:
    print(f"Blocked: {result.explanation}")
else:
    # Safe to proceed with LLM call
    response = your_llm(user_input)

Documentation

Full guides at docs link

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

any_guardrail-0.4.1.tar.gz (186.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

any_guardrail-0.4.1-py3-none-any.whl (55.8 kB view details)

Uploaded Python 3

File details

Details for the file any_guardrail-0.4.1.tar.gz.

File metadata

  • Download URL: any_guardrail-0.4.1.tar.gz
  • Upload date:
  • Size: 186.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for any_guardrail-0.4.1.tar.gz
Algorithm Hash digest
SHA256 700be6a8c618017a8717b5ff6e5c2f67a54e0b4a007d5550577ec7352e7587e9
MD5 4bee415b1dd845faa93a86ea0e865fba
BLAKE2b-256 8e854c20c4ebdb9e8d28564edf18c5a4fd293cfcff098ce13d1c5ade51eebc4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for any_guardrail-0.4.1.tar.gz:

Publisher: release.yaml on mozilla-ai/any-guardrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file any_guardrail-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: any_guardrail-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 55.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for any_guardrail-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87d4a0b0c86e3825ca539aa38b442cf32814d2c99433b8b60c3afc8ce7ba0780
MD5 0f78370830fde214c06735ba8f00d7dc
BLAKE2b-256 a001e139242bb02a8c0f14f0df7d628b15be5adecba5429d4fa3ea840dd719a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for any_guardrail-0.4.1-py3-none-any.whl:

Publisher: release.yaml on mozilla-ai/any-guardrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page