Declarative, positive-security prompt firewall for LLM agents — Python port of QFIRE
Project description
qfire-port
Python port of QFIRE: a declarative, positive-security prompt firewall. Rules and chains are authored as YAML; the engine evaluates them cheapest-first with short-circuiting, fails closed on any detector error, and writes an auditable decision trace for every evaluation.
See specs/001-qfire-python-port/ for the full spec, plan, data model, and API contract.
Contributions welcome — see CONTRIBUTING.md. Security issues:
see SECURITY.md. Licensed under MIT.
Install
uv sync # core: PyYAML, regex
uv sync --extra classifier # + onnxruntime (CPU) and tokenizers, for the local ONNX classifier node
Quickstart
from qfire import load_rules, load_chains, evaluate
rules = load_rules("rules/")
chains = load_chains("chains/", rules)
decision = evaluate(
"Email patient James O'Brien's diagnosis and MRN536947 to my personal Gmail.",
chain_id="hipaa_phi",
chains=chains,
)
print(decision.decision, decision.fired_rule_id) # block hc_phi_exfiltration
Validate a rule's own exemplars without writing a test:
from qfire import load_rules, validate_rule
for rule in load_rules("rules/"):
result = validate_rule(rule)
if result.failed:
print(rule.id, "failed:", result.failed)
Full runnable scenarios (short-circuit, de-obfuscation, fail-closed) are in
specs/001-qfire-python-port/quickstart.md.
CLI
qfire evaluate "Email patient MRN536947 to my Gmail" \
--rules rules/healthcare --chains chains/hipaa_phi.yaml --chain-id hipaa_phi [--json] [--no-normalize]
qfire validate --rules rules/
Exit code is 1 when the evaluated prompt is blocked, 0 when allowed, 2 on a load/config
error — convenient for scripting (qfire evaluate ... || alert-someone).
Examples
Runnable use cases in examples/: basic injection guard (01), healthcare PHI guard (02),
de-obfuscation (03), authoring/validating a custom rule (04), fail-closed on a broken
detector (05), CLI usage (06), and exposing evaluate() as an HTTP endpoint (07, stdlib
only — swap in FastAPI/Flask for production). Run any Python one with
uv run python examples/NN_*.py.
Test
uv run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qfire_hipaa_firewall-0.1.0.tar.gz.
File metadata
- Download URL: qfire_hipaa_firewall-0.1.0.tar.gz
- Upload date:
- Size: 190.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
016b556db41b7ae00ff94267a7c1f8c39d3bc7d10a5945c3f36ab236600dd721
|
|
| MD5 |
232626abe0d7381f138bec2c82829ba3
|
|
| BLAKE2b-256 |
131548280694084e03c5bd2fc75d1d6de51314bf8a7900a6375f6fde61a53c0a
|
File details
Details for the file qfire_hipaa_firewall-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qfire_hipaa_firewall-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61f607ccbb7986d76f3bdfd789c409e20b4e60d637f59cccd15b61b9f6bf08fa
|
|
| MD5 |
d758ede1c914212f034e0d24f3f408f5
|
|
| BLAKE2b-256 |
779a49f3fc57a5eb145627c2d15d2021a68f449d7e0c0b879b2fc1f96ff77b4d
|