Responsible AI toolkit for LLM applications -- Rust-powered PII redaction, prompt injection detection, bias scoring, and output validation with Python bindings.
pip install ferroguard==0.3.2 Copy PIP instructions
A Python library that redacts PII, scores prompts for injection patterns, scores model output for a few bias patterns, and checks that output against a small set of rules. The checks run in Rust and are called from Python through PyO3. A FastAPI app in api/ demonstrates the pipeline. It does not call a model.
pip install ferroguard import llm_guardrails The project on PyPI is ferroguard. The import name stays llm_guardrails. Wheels are abi3 for Python 3.11 and newer, so one wheel covers 3.11 through 3.14.
uv sync --all-extras uv run uvicorn api.main:app --reload What Where 🩺 Health http://localhost:8000/health 📖 Interactive API docs http://localhost:8000/docs 📄 OpenAPI document http://localhost:8000/openapi.json GET /health returns {"status":"ok","version":" "}. That version is the installed ferroguard distribution, read from package metadata. Maturin takes it from Cargo.toml. It is not hard-coded in api/main.py.
from llm_guardrails import GuardrailsPipeline pipeline = GuardrailsPipeline() pre = pipeline.pre_process("My email is alice@example.com. Summarise this report.") if pre.blocked: print(pre.injection.matched_rules) else: print(pre.sanitised_text) # "My email is >. Summarise this report." post = pipeline.post_process("Paris is the capital of France.", pre.pii_mapping) print(post.final_text) print(post.bias.score) print(post.validation.is_valid) GuardrailsPipeline takes its switches as constructor arguments (pii_enabled, injection_enabled, bias_enabled, output_validation_enabled, injection_threshold, validation_rules). .env-template lists similar names. Nothing in the library or the demo reads that file.
The demo does not call an LLM. POST /guard/full uses simulated_llm_response when you send one, and otherwise echoes a stub that quotes the sanitised prompt.
uv sync --locked --all-extras uv run ruff check . uv run ruff format --check . uv run pytest cargo fmt --check cargo clippy --all-targets -- -D warnings cargo test python3 scripts/release_subject.py --self-test python3 scripts/release_publish.py --self-test uv sync --locked --all-extras builds the extension and installs the api extra. pytest and ruff come from the default dev dependency group, not an extra. pytest needs that build because the wrappers import llm_guardrails._core. cargo test runs the Rust tests without Python. With just installed, just setup syncs the lockfile and runs maturin develop, and just ci runs the checks above plus python3 scripts/test_guardrails.py.
Two places to change when a guard's behaviour changes:
api/main.py should keep calling GuardrailsPipeline rather than growing its own checks.
FastAPI builds the document from the route functions.
text is limited to 8000 characters. A request body larger than 32768 bytes is rejected with 413 and a message that names the limit. A text field over the character limit is 422.
Breaking. /guard/input no longer returns the placeholder map. The map stays in process memory for 15 minutes under pii_mapping_id, or it is not stored at all when the map is empty. /guard/full does not store a map: restore happens inside that request, and its pii_mapping_id is null. /guard/output takes the id, pops the map, and rejects a client-supplied pii_mapping. A second call with the same id is 404, the same as an unknown or expired id. An unknown field on /guard/input or /guard/full is 422. Raw PII is not in the input response. The store is not shared: an id works only for the worker or replica that created it, and it is lost on restart. The library GuardrailsPipeline still returns the map to in-process callers; only the HTTP API hides it.
curl -s -X POST http://localhost:8000/guard/input \ -H 'Content-Type: application/json' \ -d '{"text": "My SSN is 123-45-6789. What is the weather?"}' A blocked prompt (the injection score is at least the threshold, default 0.5) comes back with "blocked": true and no output section on /guard/full.
uv run pytest cargo test pytest covers the wrappers and GuardrailsPipeline (tests/). cargo test covers the regex helpers in src/. The demo routes have no automated test yet.
The image in Dockerfile builds a wheel with maturin on python:3.12-slim, installs that wheel plus FastAPI and uvicorn[standard]>=0.54.0,<1.0, and serves api.main:app on port 8000. The Python and uv image references include a digest. Dependabot's weekly docker group opens a pull request when those digests move. The Rust compiler channel stays stable. The image downloads rustup-init 1.29.3 and checks its SHA256 before running it. Refreshing that installer means changing RUSTUP_VERSION and both architecture checksums in the same edit. Dependabot does not change those checksums.
docker build -t llm-guardrails . docker run --rm -p 8000:8000 llm-guardrails curl -s http://localhost:8000/health The image does not load .env-template. Local development uses uv and Python 3.14. PyPI publishing runs inside the release workflow. It is not a separate tag workflow.
GitHub Actions, on pull requests and on pushes to main:
The map of original PII stays in memory and is handed back to the caller. The library does not write it to disk. Discarding the map is how a caller drops those values. None of this is a complete privacy, safety, or compliance programme. Pair it with the controls your deployment actually needs, and do not send raw prompts to a model provider you have not reviewed.
CI rejects known-vulnerable and yanked Rust crates (deny.toml) and known-vulnerable Python dependencies (pip-audit).
All 6 files in this release have provenance metadata.
llm guardrails responsible-ai pii gdpr safety rust pyo3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Enable javascript to be able to filter the list of wheel files.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
All 6 files in this release have been uploaded with provenance metadata.
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.




