Small, inspectable threat-scoring library for AI-app security monitoring. Zero-dep Python port of @mukundakatta/kavach.
Project description
kavach-py
कवच -- shield, armour.
A small, inspectable threat-scoring library for AI-app security monitoring. Zero runtime dependencies.
Python port of @mukundakatta/kavach. Combines weighted detection signals with diminishing returns so stacking many weak signals can't overrule a single strong one. Returns a bounded score, a tier, a contributor list, and a recommended SOC playbook.
Install
pip install kavach-py
Usage
from kavach import score
result = score({
"promptInjection": True,
"toolMisuse": True,
"credentialLeak": False,
})
result.score # 0.545 -- bounded [0, 1]
result.tier # "medium" -- one of "low" | "medium" | "high" | "critical" (or "noise" below 0.15)
result.contributors # ["Prompt-injection language detected", "Unusual tool / API call pattern"]
result.playbook # ["DLP scanning", "egress allowlist", ...]
result.action # "Quarantine session to read-only sandbox."
You can pass any of:
- a dict mapping signal id -> truthy (matches the spec's
signals: dict), - a list/tuple/set of fired signal ids.
score(["promptInjection", "toolMisuse"]) # same result as the dict above
Use triage(signals, model=...) if you want to pin the threat model rather
than letting kavach infer it from the signals.
Signals
| Signal | Weight | What fires it |
|---|---|---|
promptInjection |
0.35 | Prompt-injection language patterns in user input |
toolMisuse |
0.30 | Unusual tool / API call pattern vs baseline |
piiExfil |
0.35 | PII detected in model output or egress |
credentialLeak |
0.45 | Credential-like string in model output |
jailbreakPattern |
0.30 | Known jailbreak template match |
rateAnomaly |
0.15 | Rate anomaly vs user baseline |
geoAnomaly |
0.15 | New geography for this account |
The SIGNALS dict is exported and mutable per-deployment.
Tiers
| Score range | Tier | Recommended action |
|---|---|---|
>= 0.85 |
critical |
Terminate session and require re-auth. |
>= 0.65 |
high |
Strip tool access and alert the on-call. |
>= 0.35 |
medium |
Quarantine session to read-only sandbox. |
>= 0.15 |
low |
Log and monitor. |
| else | noise |
Ignore. |
Threat models + playbooks
Three coarse classes of AI-app attack:
promptAbuse-- chat input, tool arguments, system prompts.dataExfiltration-- model output, file export, network egress.accountTakeover-- auth session, API token, admin console.
build_playbook(model) returns the surfaces and numbered control steps for a
given model.
API differences from the JS sibling
score(signals)accepts a dict or iterable of fired ids -- closer to the Pythonsignals: dict -> ThreatScorespec.- Returns a
ThreatScoredataclass (score,tier,contributors,model,playbook,action) instead of separatethreatScore+tier+triageIncidentcalls. - Lower-level helpers
threat_score,tier_for,recommended_action,triage,build_playbookare all available for parity.
See the JS sibling's README for broader context.
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 kavach_py-0.1.0.tar.gz.
File metadata
- Download URL: kavach_py-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25ccb5bd9cb5825d83727b77b311e23d138e808217adc1afc4aa13936a8895f6
|
|
| MD5 |
47764965e56ec365963af58923e9e3e4
|
|
| BLAKE2b-256 |
fd5f86ee06a1acbee6af6b35e6577a4a056bbeed6e485944d442826dd4ab1924
|
File details
Details for the file kavach_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kavach_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70c31a86eae92417ae580f570274ded67cc40358852e2b29fab5e51c354fba26
|
|
| MD5 |
cd0817060b38969bdc9a23611fc381cf
|
|
| BLAKE2b-256 |
e6f8735833854895070a053f7731a289d9e5ac9d8a74534cc40d4c8ef927964a
|