LLM security middleware and risk analysis layer for prompt injection detection
Reason this release was yanked:
Broken intent classifier — use 0.4.2
Project description
PromptGate
PromptGate is an open-source Python middleware library that sits between a user and an LLM and detects prompt injection risk before the model sees the input. It is a risk classifier, not a moral judge: it accumulates explainable signals and applies policy thresholds.
Architecture
user_input
→ parser (normalize text, metadata)
→ rule_based (substring pattern matching)
→ aggregator (map signals → threat categories)
→ scorer (sum unique signal severities, cap at 1.0)
→ policy (ALLOW / FLAG / REVIEW / BLOCK)
→ response (structured, explainable output)
The LLM never receives blocked prompts when PromptGate is placed in front of the request path.
Installation
From the project root (promptgate/):
pip install -e ".[dev]"
Editable install keeps pattern files and source in sync during development.
Usage
from promptgate import PromptGate
gate = PromptGate()
result = gate.check("Please ignore previous instructions.")
print(result["decision"]) # BLOCK
print(result["confidence"]) # 0.95
print(result["message"]) # Human-readable explanation
print(result["signals"]) # Matched risk signals
Custom policy thresholds:
gate = PromptGate(thresholds={"block": 0.80, "review": 0.60, "flag": 0.35})
result = gate.check(user_input)
Explainability Philosophy
Every response includes:
- decision — ALLOW, FLAG, REVIEW, or BLOCK
- confidence — equals the accumulated risk score (0.0 when safe)
- signals — what matched, with severity and pattern text
- signals_checked — signal types, categories, and pattern files scanned
- message — plain-language explanation of why the decision was made
ALLOW responses explicitly state that no injection patterns or manipulation framing were detected above thresholds. Restricted responses name matched signals and categories.
Signal accumulation is required. One weak signal alone (for example, sympathy framing) does not block. Multiple signals combine via score = min(1.0, sum(severities)).
Threat Categories
| Category | Example signals |
|---|---|
direct_injection |
instruction_override, data_exfiltration |
jailbreak |
jailbreak_persona |
system_override |
system_override, system_prompt_leak |
social_engineering |
authority_claim, secrecy_request, urgency_framing |
encoding_attack |
encoding_trick |
Severity values and mappings live in promptgate/config.py.
Default Policy Thresholds
| Score range | Decision |
|---|---|
| 0.00 – 0.29 | ALLOW |
| 0.30 – 0.54 | FLAG |
| 0.55 – 0.74 | REVIEW |
| 0.75 – 1.00 | BLOCK |
Local Testing
cd promptgate
pip install -e ".[dev]"
pytest -v
Project Layout
promptgate/
├── promptgate/ # Python package
├── data/patterns/ # Seed pattern files
├── tests/
├── pyproject.toml
└── README.md
License
MIT
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 Distributions
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 promptgate_llm-0.4.0-py3-none-any.whl.
File metadata
- Download URL: promptgate_llm-0.4.0-py3-none-any.whl
- Upload date:
- Size: 47.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74e8a4ad3cbd06bea2a3aed753b48396f567ade447e757e57512cd8559276464
|
|
| MD5 |
6dd5795bc35547e605048018aef58441
|
|
| BLAKE2b-256 |
cb0bfda480c37a59c96484e8247c74a4a39284f9f50bb1c103b71279bc39f04f
|