Skip to content

Commit 61ea0d5

Browse files
author
Paweł Kędzia
committed
Add Guardrails section to README with service table, usage instructions, configuration details, and extensibility guide.
1 parent 82795ad commit 61ea0d5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,50 @@ The services are **stateless**; they load their models once at start‑up and th
2020

2121
---
2222

23+
## 🛡️ Guardrails
24+
25+
The **guardrail** sub‑package implements safety‑checking services that can be queried via HTTP:
26+
27+
| Service | Model | Endpoint | Description |
28+
|--------------------------|-------------------------------------|------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
29+
| **NASK‑PIB Guard** | `NASK‑PIB/HerBERT‑PL‑Guard` | `POST /api/guardrails/nask_guard` | Polish‑language safety classifier detecting unsafe content (e.g., hate, violence). Returns a `safe` flag and per‑chunk classification details. |
30+
| **Sojka Guard** | `speakleash/Bielik‑Guard‑0.1B‑v1.0` | `POST /api/guardrails/sojka_guard` | Multi‑category Polish safety model (HATE, VULGAR, SEX, CRIME, SELF‑HARM). Returns detailed scores per category and an overall `safe` flag. |
31+
| **BANonymizer** (masker) | **under development** | `POST /api/maskers/banonymizer` | Token‑classification based anonymiser that redacts personal data from input text. |
32+
33+
### How to use
34+
35+
1. **Start the service** – run the provided shell script (`run_*_guardrail.sh` or `run_*_masker.sh`) or invoke the Flask
36+
module directly (e.g., `python -m llm_router_services.guardrails.speakleash.sojka_guard_app`).
37+
2. **Send a JSON payload** – the request body must be a JSON object; any string fields longer than 8 characters are
38+
extracted and classified.
39+
3. **Interpret the response** – the top‑level `safe` boolean indicates the overall verdict, while `detailed` provides
40+
per‑chunk (or per‑category) results with confidence scores.
41+
42+
### Configuration
43+
44+
All guardrail services read configuration from environment variables prefixed with:
45+
46+
* `LLM_ROUTER_NASK_PIB_GUARD_` – for the NASK‑PIB guardrail.
47+
* `LLM_ROUTER_SOJKA_GUARD_` – for the Sojka guardrail.
48+
* `LLM_ROUTER_BANONYMIZER_` – for the masker.
49+
50+
Key variables include:
51+
52+
* `MODEL_PATH` – path or Hugging‑Face hub identifier of the model.
53+
* `DEVICE``-1` for CPU or CUDA device index for GPU inference.
54+
* `FLASK_HOST` / `FLASK_PORT` – network binding for the Flask server.
55+
56+
### Extensibility
57+
58+
The guardrail architecture is built around the **`GuardrailBase`** abstract class and a **factory** (
59+
`GuardrailClassifierModelFactory`). To add a new safety model:
60+
61+
1. Implement a concrete subclass of `GuardrailBase` (or reuse `TextClassificationGuardrail`).
62+
2. Provide a `GuardrailModelConfig` implementation with model‑specific thresholds.
63+
3. Register the model type in the factory if a new identifier is required.
64+
65+
---
66+
2367
## 📜 License
2468

2569
See the [LICENSE](LICENSE) file.

0 commit comments

Comments
 (0)