fivedrisk 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. fivedrisk-0.5.0/LICENSE +201 -0
  2. fivedrisk-0.5.0/PKG-INFO +342 -0
  3. fivedrisk-0.5.0/README.md +403 -0
  4. fivedrisk-0.5.0/fivedrisk/README.md +310 -0
  5. fivedrisk-0.5.0/fivedrisk/__init__.py +140 -0
  6. fivedrisk-0.5.0/fivedrisk/__main__.py +4 -0
  7. fivedrisk-0.5.0/fivedrisk/benchmarks.py +249 -0
  8. fivedrisk-0.5.0/fivedrisk/budget_accumulator.py +167 -0
  9. fivedrisk-0.5.0/fivedrisk/classifier.py +178 -0
  10. fivedrisk-0.5.0/fivedrisk/cli.py +195 -0
  11. fivedrisk-0.5.0/fivedrisk/detectors.py +49 -0
  12. fivedrisk-0.5.0/fivedrisk/drift.py +209 -0
  13. fivedrisk-0.5.0/fivedrisk/events.py +177 -0
  14. fivedrisk-0.5.0/fivedrisk/fixtures/attacker/safe_article.txt +2 -0
  15. fivedrisk-0.5.0/fivedrisk/fixtures/attacker/webfetch_hidden_override.html +9 -0
  16. fivedrisk-0.5.0/fivedrisk/fixtures/attacker/webfetch_prompt_exfil.txt +1 -0
  17. fivedrisk-0.5.0/fivedrisk/hooks.py +959 -0
  18. fivedrisk-0.5.0/fivedrisk/langgraph_node.py +119 -0
  19. fivedrisk-0.5.0/fivedrisk/logger.py +292 -0
  20. fivedrisk-0.5.0/fivedrisk/markov.py +368 -0
  21. fivedrisk-0.5.0/fivedrisk/policy.py +208 -0
  22. fivedrisk-0.5.0/fivedrisk/router.py +236 -0
  23. fivedrisk-0.5.0/fivedrisk/schema.py +383 -0
  24. fivedrisk-0.5.0/fivedrisk/scorer.py +236 -0
  25. fivedrisk-0.5.0/fivedrisk/tests/__init__.py +0 -0
  26. fivedrisk-0.5.0/fivedrisk/tests/test_acting_identity.py +107 -0
  27. fivedrisk-0.5.0/fivedrisk/tests/test_atlas_coverage.py +201 -0
  28. fivedrisk-0.5.0/fivedrisk/tests/test_budget_accumulator.py +121 -0
  29. fivedrisk-0.5.0/fivedrisk/tests/test_budget_enforcement_integration.py +148 -0
  30. fivedrisk-0.5.0/fivedrisk/tests/test_classifier.py +108 -0
  31. fivedrisk-0.5.0/fivedrisk/tests/test_classifier_capability.py +110 -0
  32. fivedrisk-0.5.0/fivedrisk/tests/test_classifier_per_dim.py +224 -0
  33. fivedrisk-0.5.0/fivedrisk/tests/test_cli_benchmarks.py +149 -0
  34. fivedrisk-0.5.0/fivedrisk/tests/test_drift.py +248 -0
  35. fivedrisk-0.5.0/fivedrisk/tests/test_drift_capability.py +171 -0
  36. fivedrisk-0.5.0/fivedrisk/tests/test_golden_set.py +64 -0
  37. fivedrisk-0.5.0/fivedrisk/tests/test_hooks.py +258 -0
  38. fivedrisk-0.5.0/fivedrisk/tests/test_logger.py +208 -0
  39. fivedrisk-0.5.0/fivedrisk/tests/test_logger_capability.py +170 -0
  40. fivedrisk-0.5.0/fivedrisk/tests/test_markov.py +273 -0
  41. fivedrisk-0.5.0/fivedrisk/tests/test_ndjson_events.py +146 -0
  42. fivedrisk-0.5.0/fivedrisk/tests/test_policy_budget_attributes.py +71 -0
  43. fivedrisk-0.5.0/fivedrisk/tests/test_router.py +139 -0
  44. fivedrisk-0.5.0/fivedrisk/tests/test_router_capability.py +147 -0
  45. fivedrisk-0.5.0/fivedrisk/tests/test_runtime_benchmarks.py +201 -0
  46. fivedrisk-0.5.0/fivedrisk/tests/test_runtime_controls.py +168 -0
  47. fivedrisk-0.5.0/fivedrisk/tests/test_scorer.py +201 -0
  48. fivedrisk-0.5.0/fivedrisk/tests/test_scorer_capability.py +159 -0
  49. fivedrisk-0.5.0/fivedrisk/token_costs.py +116 -0
  50. fivedrisk-0.5.0/fivedrisk.egg-info/PKG-INFO +342 -0
  51. fivedrisk-0.5.0/fivedrisk.egg-info/SOURCES.txt +55 -0
  52. fivedrisk-0.5.0/fivedrisk.egg-info/dependency_links.txt +1 -0
  53. fivedrisk-0.5.0/fivedrisk.egg-info/entry_points.txt +2 -0
  54. fivedrisk-0.5.0/fivedrisk.egg-info/requires.txt +8 -0
  55. fivedrisk-0.5.0/fivedrisk.egg-info/top_level.txt +2 -0
  56. fivedrisk-0.5.0/pyproject.toml +83 -0
  57. fivedrisk-0.5.0/setup.cfg +4 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend, and
172
+ hold each Contributor harmless for any liability incurred by, or
173
+ claims asserted against, such Contributor by reason of your accepting
174
+ any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed" page as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Loren Angoni
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing permissions
201
+ and limitations under the License.
@@ -0,0 +1,342 @@
1
+ Metadata-Version: 2.4
2
+ Name: fivedrisk
3
+ Version: 0.5.0
4
+ Summary: Per-action AI agent risk scoring and governance: 5-dimension scoring, HITL enforcement, Markov drift detection, injection scanning, and auditable decision logs.
5
+ Author: Loren Angoni
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/theDoc001/fivedrisk
8
+ Project-URL: Repository, https://github.com/theDoc001/fivedrisk
9
+ Project-URL: Bug Tracker, https://github.com/theDoc001/fivedrisk/issues
10
+ Project-URL: Changelog, https://github.com/theDoc001/fivedrisk/blob/main/CHANGELOG.md
11
+ Keywords: ai-safety,ai-governance,agent-safety,llm-safety,prompt-injection,hitl,risk-scoring,audit-log,markov-drift,owasp,langgraph,claude,anthropic
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: PyYAML>=6.0
26
+ Provides-Extra: langgraph
27
+ Requires-Dist: langgraph>=0.2.3; extra == "langgraph"
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8.0; extra == "dev"
30
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # fivedrisk — AI Agent Risk Governance Engine
34
+
35
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
36
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
37
+ [![Tests](https://github.com/theDoc001/fivedrisk/actions/workflows/tests.yml/badge.svg)](https://github.com/theDoc001/fivedrisk/actions/workflows/tests.yml)
38
+
39
+ **Per-action risk scoring and governance for AI agents.** Drop one decorator on your tool functions, or wire in the Agent SDK hooks — every action is scored, gated, and logged before it runs.
40
+
41
+ ```python
42
+ from fivedrisk.hooks import gate
43
+
44
+ @gate(tool_name="write_to_database", autonomy_context=2)
45
+ async def write_record(table: str, data: dict) -> None:
46
+ ... # only executes if 5D scores GREEN or YELLOW
47
+ # ORANGE → human approval required
48
+ # RED → blocked, never runs
49
+ ```
50
+
51
+ ---
52
+
53
+ ## What it does
54
+
55
+ fivedrisk scores every AI agent action on **5 risk dimensions** (0–4 each):
56
+
57
+ | Dimension | What it measures |
58
+ |---|---|
59
+ | **D** — Data Sensitivity | Public → PII → financial → credentials |
60
+ | **T** — Tool Privilege | Read-only → write → admin → destructive |
61
+ | **R** — Reversibility | Undoable → hard-to-undo → irreversible |
62
+ | **E** — External Impact | Local → internal API → external → untrusted |
63
+ | **A** — Autonomy Context | User-direct → agent-supervised → fully autonomous |
64
+
65
+ 5D stays deterministic. Bands signal what fivedrisk wants your stack to do; your stack chooses the LLM and the workflow.
66
+
67
+ **Default 3-band:**
68
+
69
+ - **GREEN** — execute, normal logging.
70
+ - **ORANGE** — HITL approval required. fivedrisk signals; your stack handles the LLM choice. No auto model promotion.
71
+ - **RED** — blocked.
72
+
73
+ **Opt-in 4-band compliance mode** (`enable_yellow_band: true` in `policy.yaml`): surfaces YELLOW as a stable moderate-risk tier for audit queries and dashboards. Optional model escalation within YELLOW via `yellow_model_escalation: true`.
74
+
75
+ fivedrisk is one layer in a defence-in-depth AI governance stack.
76
+
77
+ ---
78
+
79
+ ## Features
80
+
81
+ - **5D scoring engine** — deterministic, ~40µs per action (p50) on M1, no LLM calls
82
+ - **Markov SafetyDrift** — 16-state Markov chain detects cumulative risk across action sequences; catches compositional attacks that individual scoring misses
83
+ - **Session accumulator** — O(1) counter-based drift tracking for the common case
84
+ - **Injection scanner** — 24+ regex patterns covering GPT-5/Opus-era evasion (Base64, zero-width Unicode, role hijacks, encoded exec calls)
85
+ - **Output leakage scanner** — PII, credentials, crypto keys, injection-echo detection
86
+ - **`@gate` decorator** — wrap any sync or async function with full 5D gating
87
+ - **Agent SDK hooks** — `fivedrisk_pre_tool` / `fivedrisk_post_tool` for Anthropic Agent SDK
88
+ - **LangGraph node** — drop-in integration for LangGraph pipelines
89
+ - **Destination policy** — allowlist/denylist for outbound endpoints
90
+ - **Audit log** — append-only SQLite decision log plus optional NDJSON event stream for SIEM delivery
91
+ - **Policy floor enforcement** — floor rules in `policy.yaml` cannot be overridden at runtime
92
+ - **Defence-in-depth test suite** — pytest markers per OWASP LLM Top 10 category, plus 39-scenario attack-class benchmark (`python -m fivedrisk benchmark`)
93
+ - **424 tests** with 0 failures
94
+
95
+ ---
96
+
97
+ ## Install
98
+
99
+ ```bash
100
+ pip install fivedrisk
101
+ ```
102
+
103
+ For LangGraph integration:
104
+ ```bash
105
+ pip install "fivedrisk[langgraph]"
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Quick start (30 seconds)
111
+
112
+ ```python
113
+ from fivedrisk import classify_tool_call, score, load_policy, Band
114
+
115
+ policy = load_policy("policy.yaml") # or use defaults
116
+ action = classify_tool_call("Bash", {"command": "rm -rf /tmp/cache"}, policy)
117
+ result = score(action, policy)
118
+
119
+ print(result.band) # Band.ORANGE
120
+ print(result.rationale) # "ORANGE — Bash: Reversibility=3 (≥ ORANGE threshold 3)"
121
+ print(result.routing) # RoutingDecision(model_floor=M3, approval_required=True)
122
+ ```
123
+
124
+ **With the `@gate` decorator:**
125
+ ```python
126
+ from fivedrisk.hooks import gate, configure
127
+ from fivedrisk import load_policy
128
+
129
+ configure(policy=load_policy("policy.yaml"))
130
+
131
+ @gate(tool_name="send_email", autonomy_context=1)
132
+ def send_email(to: str, body: str) -> None:
133
+ # only executes if 5D scores GREEN or YELLOW
134
+ smtp.send(to, body)
135
+ ```
136
+
137
+ **With Anthropic Agent SDK:**
138
+ ```python
139
+ from fivedrisk.hooks import fivedrisk_pre_tool, fivedrisk_post_tool
140
+
141
+ # Register as PreToolUse and PostToolUse hooks in your agent
142
+ ```
143
+
144
+ **With LangGraph:**
145
+ ```python
146
+ from fivedrisk.langgraph_node import fivedrisk_gate_node
147
+ # Add fivedrisk_gate_node to your StateGraph before any tool-executing node
148
+ ```
149
+
150
+ ---
151
+
152
+ ## SafetyDrift — why sequence risk matters
153
+
154
+ A single READ of a config file scores GREEN. But 10 GREENs followed by a write to an external API using credentials extracted two steps earlier is a RED sequence. Most tools miss this.
155
+
156
+ fivedrisk tracks cumulative session state via a **16-state Markov chain** over `(data_exposure_tier × activity_risk_tier)`. When absorption probability into a dangerous state crosses 0.3, the next action is escalated to ORANGE. At 0.7, it's escalated to RED.
157
+
158
+ ```python
159
+ from fivedrisk.markov import MarkovDriftTracker, make_default_transition_matrix
160
+
161
+ tracker = MarkovDriftTracker(make_default_transition_matrix(), session_id="abc")
162
+ bump = tracker.record(scored_action)
163
+ if bump:
164
+ print(f"Drift: {bump.reason}, escalated to {bump.escalated_band}")
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Policy configuration
170
+
171
+ ```yaml
172
+ # policy.yaml
173
+ thresholds:
174
+ red_threshold: 4
175
+ orange_threshold: 3
176
+ orange_score: 1.8
177
+ yellow_score: 1.0
178
+
179
+ [floor]
180
+ # These rules block regardless of per-action score
181
+ - tool_name: "Bash"
182
+ command_contains: "DROP TABLE"
183
+ band: RED
184
+ reason: "floor:no-destructive-sql"
185
+ ```
186
+
187
+ ---
188
+
189
+ ## Benchmark
190
+
191
+ ```bash
192
+ python -m fivedrisk benchmark
193
+ ```
194
+
195
+ Runs 39 offline attack scenarios across: prompt injection (12 categories), output leakage (8 categories), runtime tool misuse (19 scenarios). No external API calls. Deterministic. Safe to run in CI.
196
+
197
+ ---
198
+
199
+ ## Performance
200
+
201
+ Measured on Apple M1, single-thread. Reproducible from `benchmarks/bench_minimal.py`.
202
+
203
+ | Operation | p50 | p99 |
204
+ |---|---|---|
205
+ | **5D core (classify + score)** | **40µs** | **42µs** |
206
+ | Injection scan, 30 char clean | 11µs | 12µs |
207
+ | Injection scan, 3000 char clean | 669µs | 685µs |
208
+ | Leakage scan, 200 char clean | 23µs | 23µs |
209
+ | 5D + injection + leakage scan | 64µs | 65µs |
210
+ | 5D + Markov drift | 43µs | 44µs |
211
+ | 5D + SQLite audit-log write (I/O) | 440µs | 1ms |
212
+ | `@gate` sync overhead (incl. log write) | 439µs | 1.1ms |
213
+ | `@gate` async overhead | 421µs | 660µs |
214
+
215
+ External optional layers (not in fivedrisk):
216
+
217
+ - [PromptArmor](https://promptarmor.com): ~20-30ms typical
218
+ - [LLM Guard](https://llm-guard.com) (token scanners): ~10-15ms typical
219
+ - [LLM Guard](https://llm-guard.com) (ML scanners): ~50-200ms typical
220
+
221
+ Injection scanner is linear in input length; for large RAG contexts, chunk and parallelize. Run the bench script on your target hardware for numbers that match your install.
222
+
223
+ ---
224
+
225
+ ## Audit log
226
+
227
+ fivedrisk produces an append-only decision log entry for every agent action. Each entry records:
228
+ - Risk band and rationale
229
+ - Dimension scores (all 5 axes)
230
+ - Model routing decision and approval history
231
+ - Session drift state
232
+ - Injection and leakage scan results
233
+ - Optional agent identity claim (see below)
234
+
235
+ ### Agent identity passthrough
236
+
237
+ fivedrisk accepts opaque agent identity claims through `Action.metadata["agent_identity"]`. The string flows through unchanged into the audit log for SOC/SIEM correlation. SVID, JWT, and X.509 subject strings are supported as opaque data today.
238
+
239
+ ```python
240
+ action.metadata["agent_identity"] = "spiffe://example.org/agents/triage-bot"
241
+ ```
242
+
243
+ Cryptographic validation, structured parsing, and identity-aware policy hooks are post-OSS scope.
244
+
245
+ ### Reserved metadata keys
246
+
247
+ - `agent_identity` — opaque identity claim string. Do not overwrite with arbitrary values.
248
+
249
+ ---
250
+
251
+ ## Identity capture
252
+
253
+ `Action.acting_identity` is a typed pass-through primitive for the principal an action is being taken on behalf of. Distinct from `agent_identity` (the AI agent's own workload identity); `acting_identity` is who authorized the action.
254
+
255
+ ```python
256
+ from fivedrisk import gate, ActingIdentity, PrincipalType, AttestationSource
257
+
258
+ ai = ActingIdentity(
259
+ principal_id="user-42",
260
+ principal_type=PrincipalType.USER,
261
+ attestation_source=AttestationSource.HTTP_HEADER,
262
+ )
263
+
264
+ # Per-call override
265
+ fn("...", session_id="s1", _fivedrisk_acting_identity=ai)
266
+ ```
267
+
268
+ Declare `identity_required: true` in `policy.yaml` to deny actions where the caller supplied no identity. The deny surfaces as `IdentityRequiredError` and emits an `identity_required_denial` NDJSON event.
269
+
270
+ Identity-aware policy evaluation beyond admission, cryptographic validation, and SPIFFE/SPIRE native binding are post-OSS scope.
271
+
272
+ ---
273
+
274
+ ## Cost management primitives
275
+
276
+ Per-session token budgeting with direct DENY at @gate when a reservation would exceed the session cap.
277
+
278
+ ```yaml
279
+ # policy.yaml
280
+ max_session_budget_tokens: 100000
281
+ max_tool_call_budget_tokens: 4096
282
+ ```
283
+
284
+ ```python
285
+ from fivedrisk import gate, configure
286
+
287
+ configure(event_path="audit.ndjson", default_model_class="claude-sonnet-class")
288
+
289
+ @gate(tool_name="summarize", estimated_input_tokens=2000)
290
+ def summarize(text: str, session_id: str) -> str:
291
+ ...
292
+ ```
293
+
294
+ If the projected token spend exceeds `max_session_budget_tokens`, @gate raises `BudgetExceededError` and emits a `budget_intervention` NDJSON event.
295
+
296
+ Additional Operational FinOps capabilities (Tool Manifest admission layers, useful-progress monitoring, multi-agent budget envelopes, wall-clock / retry / delegation caps) are on the project roadmap.
297
+
298
+ ---
299
+
300
+ ## Planned
301
+
302
+ Future capability surfaces signalled here for search and contributor expectations. No commitment dates.
303
+
304
+ - SPIFFE / MCP reference example (end-to-end workload identity demo)
305
+ - MITRE ATLAS coverage with real tests
306
+ - NIST AI RMF mapping
307
+ - OWASP Agentic Top 10 coverage doc
308
+ - Regulatory crosswalks (AI Act Article 12, NIS2, DORA, ISO 42001)
309
+ - Decision log analysis cookbook (sample SQL for common compliance queries)
310
+
311
+ ---
312
+
313
+ ## Architecture
314
+
315
+ ```
316
+ fivedrisk/
317
+ ├── schema.py # Band, Action, ScoredAction, HITLCard, ModelClass
318
+ ├── scorer.py # score(), model routing (§12-19)
319
+ ├── classifier.py # classify_tool_call() with policy baselines
320
+ ├── hooks.py # @gate, Agent SDK hooks, injection/leakage scanners
321
+ ├── drift.py # SessionAccumulator (O(1) counter-based)
322
+ ├── markov.py # MarkovDriftTracker, Gauss-Jordan, absorption probs
323
+ ├── detectors.py # Versioned detector corpus (2026-04-14.2)
324
+ ├── policy.py # Policy dataclass + YAML loader
325
+ ├── router.py # ModelRouter, EscalationSignal
326
+ ├── logger.py # DecisionLog (SQLite, append-only)
327
+ ├── langgraph_node.py# LangGraph integration
328
+ ├── benchmarks.py # 39-case offline benchmark harness
329
+ └── tests/ # 424 tests
330
+ ```
331
+
332
+ **Coverage**: 14/21 governance spec sections fully implemented.
333
+
334
+ ---
335
+
336
+ ## License
337
+
338
+ Apache 2.0. See [LICENSE](LICENSE).
339
+
340
+ Built by [Loren Angoni](https://langoni.me). Contributions welcome.
341
+
342
+ > "An ambition that doesn't get executed is a hallucination."