Skip to main content

A safety layer between your application and any LLM API — input/output firewalling, PII redaction, jailbreak detection, and domain-specific guardrails.

Project description

llmfw — LLM Firewall

A safety layer between your application and any LLM API. It inspects prompts (input) and responses (output), applies a set of default checks, and optionally applies extra domain-specific checks (finance, medical, legal, ...). Ships with a local dashboard to visualize what got flagged or blocked over time.

Install

pip install llmfw            # core
pip install llmfw[dashboard] # + local dashboard (FastAPI/uvicorn)
pip install llmfw[all]       # everything

Quickstart

from llmfw import Firewall

fw = Firewall(domain="finance")

result = fw.check_input(user_prompt)
if not result.allowed:
    return "Request blocked: " + result.blocked_by

response = call_llm(result.redacted_text)

out_result = fw.check_output(response)
if not out_result.allowed:
    return "Response blocked"

return out_result.redacted_text

Or wrap the whole request/response cycle in one call:

result = fw.protect(user_prompt, llm_call_fn=call_llm)

See examples/quickstart.py for a runnable version.

What it checks

Default detectors (always run):

  • Injection — prompt injection / jailbreak detection (pattern, structural, and paraphrase matching)
  • PII — emails, phone numbers, SSNs, card numbers (Luhn-validated), IPs — redacted in place
  • Output validator — schema/length checks, basic hallucination markers
  • Leak guard — detects system-prompt-like content leaking into output
  • Multi-turn tracker — flags cumulative suspicious patterns across a session
  • Toxicity — hate speech / self-harm / abuse filter
  • Obfuscation — decodes base64/unicode/leetspeak tricks before re-running the other checks

Domain packs (opt-in via domain=):

  • finance — guaranteed-return scam phrasing, unlicensed investment advice, pump-and-dump/fake-ticker hype
  • medical — unlicensed diagnosis/prescription language, unsafe dosage mentions, patient-identifiable health info (PHI)
  • legal — unauthorized legal advice/guaranteed-outcome phrasing, unverified case citations flagged for human review

CLI

llmfw check "some prompt" --domain finance
llmfw dashboard              # launch the local dashboard at localhost:8420
llmfw test --domain finance  # run the curated attack-prompt suite

Dashboard

llmfw dashboard starts a local FastAPI server (requires the dashboard extra) that serves a small UI showing recent blocked/flagged events, a breakdown by rule and domain, and a blocks-per-day trend. Events are logged to a local SQLite database (llmfw_events.db by default).

Configuration

# llmfw.config.yaml
domain: finance
enabled_detectors:
  - injection
  - pii
  - output_validator
  - leak_guard
  - multiturn_tracker
  - toxicity
  - obfuscation
thresholds:
  injection: 0.6
log_events: true
db_path: llmfw_events.db
fw = Firewall(config="llmfw.config.yaml")

Testing

pip install -e ".[dev,dashboard]"
pytest tests/
python -m tests.benchmark   # false-positive / false-negative rate per domain

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llmfw-0.1.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llmfw-0.1.0-py3-none-any.whl (35.7 kB view details)

Uploaded Python 3

File details

Details for the file llmfw-0.1.0.tar.gz.

File metadata

  • Download URL: llmfw-0.1.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for llmfw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 35a686907c428ae6d594bd476b35e3de3a35a4d78303ea9447279b294f8d6dc2
MD5 f5791926de9254598b3e83b8e82b5855
BLAKE2b-256 c7c70a05f283b0f699fd2b9ed946539fd9c3a0107ee15cab5517e326d7b8b37e

See more details on using hashes here.

File details

Details for the file llmfw-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llmfw-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 35.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for llmfw-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63ca3bdae2553f04e0aae341d61a017a9a624979759dc991eeac2b381881bbbb
MD5 17e1c465994c763da2b0e7af7c8c0068
BLAKE2b-256 133a08981ed7fff3d8fecb46dbd51bed6bf2bbf32f15fb2924585ee12b86c6f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page