Skip to main content

guardrails-ai-restrict-to-topic

Checks that a text's topic is within a set of valid topics and, optionally, that it avoids a set of invalid topics. By default it runs a local zero-shot classifier (facebook/bart-large-mnli) and falls back to an LLM when the classifier is not confident.

Registered as tryolabs/restricttotopic.

Installation

pip install guardrails-ai-restrict-to-topic

Usage

from guardrails import Guard
from guardrails_ai.restricttotopic import RestrictToTopic

guard = Guard().use(
    RestrictToTopic(
        valid_topics=["sports", "politics"],
        invalid_topics=["music"],
        disable_llm=True,  # zero-shot classifier only (no OpenAI key needed)
        on_fail="exception",
    )
)

guard.validate("The Chiefs won the Super Bowl.")  # passes

The default ensemble mode also uses an LLM fallback and requires OPENAI_API_KEY.

License

Apache-2.0. Originally authored by Tryolabs.

Metadata

Release files for guardrails-ai-restrict-to-topic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for guardrails-ai-restrict-to-topic 0.1.0
File Size Uploaded Provenance
guardrails_ai_restrict_to_topic-0.1.0.tar.gz 11.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for guardrails-ai-restrict-to-topic 0.1.0
File Interpreter ABI Platform
guardrails_ai_restrict_to_topic-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.2 kB

Release files / guardrails_ai_restrict_to_topic-0.1.0.tar.gz

Download URL guardrails_ai_restrict_to_topic-0.1.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d224ce95d6d9bbbbe628d6a56af251c1760bfff8640d9a15bd2421290d155580
BLAKE2b-256 checksum
How to use checksums
a58a83182831ee622183055fdf9fe0911a42d43e997f90cbe43ab73896f7e59d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / guardrails_ai_restrict_to_topic-0.1.0-py3-none-any.whl

Download URL guardrails_ai_restrict_to_topic-0.1.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f64ed9b7fcf452a27dd490fa613025dc9452a53ed6b828d7aa7ab5b981d6821b
BLAKE2b-256 checksum
How to use checksums
9ee8f101691d8a5efe16db941c4368652cc019000d2d06bfddc244fe625a32cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Security for guardrails-ai-restrict-to-topic 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page