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.
Metadata
Release files for kavach-py 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kavach_py-0.1.0.tar.gz | 6.8 kB | Without provenance | Details for kavach_py-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kavach_py-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for kavach_py-0.1.0-py3-none-any.whl |
Total release size: 13.6 kB
Release files / kavach_py-0.1.0.tar.gz
| Download URL | kavach_py-0.1.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25ccb5bd9cb5825d83727b77b311e23d138e808217adc1afc4aa13936a8895f6
|
|
BLAKE2b-256 checksum How to use checksums |
fd5f86ee06a1acbee6af6b35e6577a4a056bbeed6e485944d442826dd4ab1924
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / kavach_py-0.1.0-py3-none-any.whl
| Download URL | kavach_py-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
70c31a86eae92417ae580f570274ded67cc40358852e2b29fab5e51c354fba26
|
|
BLAKE2b-256 checksum How to use checksums |
e6f8735833854895070a053f7731a289d9e5ac9d8a74534cc40d4c8ef927964a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for kavach-py 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.