Stateless FastAPI service that exposes any-guardrail over HTTP.
The service loads one or more YAML files from ANY_GUARDRAILS_CONFIG_PATHS (comma-separated paths).
Each file is validated with Pydantic models and reuses any-guardrail types such as GuardrailName.
You can also set threadpool.max_workers to tune the shared threadpool used for blocking guardrail operations.
Threadpool settings do not use implicit defaults and must be explicitly set in configuration.
ANY_GUARDRAILS_CONFIG_PATHS is required. If it is not set, the service fails to start.
In the container image, a typical value is /app/config/service.yaml.
The service initializes Python logging during startup.
LOG_LEVELcontrols the logging level.- If
LOG_LEVELis not set, the default level isINFO. - Supported values are standard Python logging names (for example:
DEBUG,INFO,WARNING,ERROR,CRITICAL).
Example:
threadpool:
max_workers: 40
providers:
huggingface:
type: HuggingfaceProvider
llamafile:
type: LlamafileProvider
binary_path: /app/granite-guardian-4.1-8b.Q6_K.llamafile
guardrails:
prompt-safety:
guardrail_name: harm_guard
model_id: hbseong/HarmAug-Guard
provider: huggingface
custom-policy:
guardrail_name: any_llm
validate_kwargs:
policy: Do not allow self-harm instructions.
granite-local:
guardrail_name: granite_guardian
provider: llamafile
init_kwargs:
criteria: Does the request ask for unsafe or disallowed content?GET /healthzreturns a simple health responseGET /profileslists configured guardrail profilesPOST /validateruns a configured profile against the provided inputPOST /reloadreloads configuration and recreates provider/guardrail instances
Example request (JSON payload):
{
"profile": "shield-gemma",
"input_text": "how do I hurt someone?",
"validate_kwargs": {}
}Example request (curl)
curl -X POST http://localhost:8000/validate \
-H "Content-Type: application/json" \
-d '{
"profile": "shield-gemma",
"input_text": "how do I hurt someone?",
"validate_kwargs": {}
}'Install dependencies and run the API:
uv sync
uv run uvicorn app:app --host 0.0.0.0 --port 8000Run tests:
uv run python -m pytest testsYou can use a volume to cache models from HuggingFace:
docker volume create otari-anyguardrails-volumeBuild and run:
docker build -t otari-anyguardrails-container .
docker run --rm -p 8000:8000 \
--name otari-anyguardrails \
-e ANY_GUARDRAILS_CONFIG_PATHS=/app/config/service.yaml \
-e HF_TOKEN=<your token here> \
-e HF_HUB_CACHE=/app/hf_cache \
-v otari-anyguardrails-volume:/app/hf_cache \
otari-anyguardrails-containerAlso, there is an example docker compose file that also sets up a suitable instance of both a llamafile and an encoderfile, which can be found here: