Metadata-Version: 2.4
Name: guardrails-ai-restrict-to-topic
Version: 0.1.1a1
Summary: Checks that a text stays on a set of valid topics and avoids invalid ones.
Author: Tryolabs
License-Expression: Apache-2.0
Project-URL: Homepage, https://guardrailsai.com
Project-URL: Repository, https://github.com/guardrails-ai/guardrails-hub-monorepo/tree/main/restricttotopic/py
Project-URL: Documentation, https://github.com/guardrails-ai/guardrails-hub-monorepo/blob/main/restricttotopic/py/README.md
Requires-Python: <4,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: guardrails-ai>=0.4.0
Requires-Dist: pydantic>=2.4.2
Requires-Dist: tenacity>=8.1.0
Requires-Dist: transformers>=4.11.3
Requires-Dist: torch>=2.1.1
Requires-Dist: openai
Requires-Dist: python-dotenv
Provides-Extra: dev
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: coverage>=7.6.12; extra == "dev"
Requires-Dist: pyright[nodejs]>=1.1.396; extra == "dev"
Dynamic: license-file

# 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

```bash
pip install guardrails-ai-restrict-to-topic
```

## Usage

```python
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.
