llm-router/docs

Guardrails Package#

guardrails provides the core safety‑checking services used by llm‑router, alongside the PII maskers package. All enabled services are mounted on a single Flask application (llm_router_services/router.py) that exposes a simple HTTP API called by the corresponding llm‑router plugin.

Sub‑packages#

Paths are relative to llm_router_services/.

Path Purpose
guardrails/inference/ Shared text‑classification engine, config interfaces and chunk scoring.
guardrails/payload_handler.py Extracts textual elements from an arbitrary JSON payload.
guardrails/nask/ NASK‑PIB safety model (Polish text classification).
guardrails/speakleash/ Sojka (Bielik‑Guard) safety model (multi‑category).
maskers/pii_classification/ PII masker – token‑classification anonymiser with a bounded in‑memory cache.
router.py Builds the Flask app and registers every service whose *_ENABLED flag is on.
../../run_servcices.sh Starts all enabled services in a single Gunicorn process.

HTTP API#

All guardrail endpoints share the same request format:

{
  "payload": "<any JSON value>"
}
  • payload may be a string, object, list, or any JSON‑serialisable type.
  • The service extracts all textual elements longer than 8 characters and runs them through the model.
  • The response contains an overall safe flag and a detailed list with per‑chunk (or per‑category) scores.
  • Non‑JSON request bodies are rejected with 400; inference failures return 500 with {"error": "…"}.

Masker endpoints (/api/maskers/<name>) accept the same payload and answer with {"anonymized": …, "mappings": …}.

Running the services#

There is a single entry point – enable the services you need:

shell script LLM_ROUTER_NASK_PIB_GUARD_ENABLED=1 \ LLM_ROUTER_NASK_PIB_GUARD_MODEL_PATH=NASK-PIB/Herbert-PL-Guard \ ./run_servcices.sh

See the project README for the full list of environment variables.

Guardrail Services Documentation#

llm-router · docs are generated from the repository by tools/build_docs.py 1.1.6 @ d1b9641