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)
Every guardrail returns the same GuardrailOutput shape, so you can swap models without changing application code:
result.valid # bool verdict — True means the content passed
result.score # risk score in ~[0, 1], higher = more likely violating (when available)
result.categories # per-category results: CategoryResult(name, description, triggered, score, severity)
result.explanation # human-readable rationale (judge reasoning, raw generation)
result.action # provider-recommended action (e.g. "block"), advisory; None if none
result.usage # provenance: model_id, latency_ms, token counts
result.extra # guardrail-specific structured extras; result.raw holds the backend payload
flagged = [c.name for c in result.categories if c.triggered]
A machine-readable JSON Schema for this output is published in the repo (generated from the Pydantic models). Reference it at the stable raw URL, pinning a release tag for a specific version:
https://raw.githubusercontent.com/mozilla-ai/any-guardrail/main/schemas/guardrail_output.schema.json
Prompts, policies, rubrics & criteria
Generative and judge guardrails run against a prompt template and often need a policy, rubric, or criteria. any-guardrail lets you discover and override the default prompt, and fetch author-published policies/rubrics/criteria — all without loading a model:
from any_guardrail import AnyGuardrail, GuardrailName
# Inspect a guardrail's default prompt template
AnyGuardrail.get_prompt(GuardrailName.SELENE).segments["user"]
# Fetch a ready-made author-published policy and use it directly
policy = AnyGuardrail.get_policy(GuardrailName.SHIELD_GEMMA, "dangerous_content")
guard = AnyGuardrail.create(GuardrailName.SHIELD_GEMMA, policy=policy)
See the Prompts & content guide. The catalogs are exported to
schemas/guardrail_prompts.json and
schemas/guardrail_content.json.
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.
Metadata
Release files for any-guardrail 0.7.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| any_guardrail-0.7.7.tar.gz | 579.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| any_guardrail-0.7.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 849.9 kB
Release files / any_guardrail-0.7.7.tar.gz
| Download URL | any_guardrail-0.7.7.tar.gz |
|---|---|
| Size | 579.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a348c624a4da77da56372d68c44128d9103bf1a0d512ab75a701937e332b4457
|
|
BLAKE2b-256 checksum How to use checksums |
60690ad6966c0ea9d862eec090c71bc712a664473852f0e87afadf674155dcb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.
Transparency logRelease files / any_guardrail-0.7.7-py3-none-any.whl
| Download URL | any_guardrail-0.7.7-py3-none-any.whl |
|---|---|
| Size | 270.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a14aff794bdba8729755a69e0a0107d2ec8f49fdf5cce388544f853be80928b8
|
|
BLAKE2b-256 checksum How to use checksums |
a78a4061430c06f7a4f2d1fbc99f8a878ca94ca15b3f648600d943d19f4df500
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.
Transparency logSecurity for any-guardrail 0.7.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for any_guardrail-0.7.7.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.