admina-framework 0.9.0__py3-none-any.whl

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 (102) hide show
  1. admina/__init__.py +34 -0
  2. admina/cli/__init__.py +14 -0
  3. admina/cli/commands/__init__.py +14 -0
  4. admina/cli/main.py +1522 -0
  5. admina/cli/templates/admina.yaml.j2 +77 -0
  6. admina/cli/templates/docker-compose.yml.j2 +254 -0
  7. admina/cli/templates/env.j2 +10 -0
  8. admina/cli/templates/main.py.j2 +95 -0
  9. admina/cli/templates/plugin.py.j2 +145 -0
  10. admina/cli/templates/plugin_pyproject.toml.j2 +15 -0
  11. admina/cli/templates/plugin_readme.md.j2 +27 -0
  12. admina/cli/templates/plugin_test.py.j2 +48 -0
  13. admina/core/__init__.py +14 -0
  14. admina/core/config.py +497 -0
  15. admina/core/event_bus.py +112 -0
  16. admina/core/secrets.py +257 -0
  17. admina/core/types.py +146 -0
  18. admina/dashboard/__init__.py +8 -0
  19. admina/dashboard/static/heimdall.png +0 -0
  20. admina/dashboard/static/index.html +1045 -0
  21. admina/dashboard/static/vendor/alpinejs.min.js +5 -0
  22. admina/domains/__init__.py +14 -0
  23. admina/domains/agent_security/__init__.py +41 -0
  24. admina/domains/agent_security/firewall.py +634 -0
  25. admina/domains/agent_security/loop_breaker.py +176 -0
  26. admina/domains/ai_infra/__init__.py +79 -0
  27. admina/domains/ai_infra/llm_engine.py +477 -0
  28. admina/domains/ai_infra/rag.py +817 -0
  29. admina/domains/ai_infra/webui.py +292 -0
  30. admina/domains/compliance/__init__.py +109 -0
  31. admina/domains/compliance/cross_regulation.py +314 -0
  32. admina/domains/compliance/eu_ai_act.py +367 -0
  33. admina/domains/compliance/forensic.py +380 -0
  34. admina/domains/compliance/gdpr.py +331 -0
  35. admina/domains/compliance/nis2.py +258 -0
  36. admina/domains/compliance/oisg.py +658 -0
  37. admina/domains/compliance/otel.py +101 -0
  38. admina/domains/data_sovereignty/__init__.py +42 -0
  39. admina/domains/data_sovereignty/classification.py +102 -0
  40. admina/domains/data_sovereignty/pii.py +260 -0
  41. admina/domains/data_sovereignty/residency.py +121 -0
  42. admina/integrations/__init__.py +14 -0
  43. admina/integrations/_engines.py +63 -0
  44. admina/integrations/cheshirecat/__init__.py +13 -0
  45. admina/integrations/cheshirecat/admina-plugin/admina_governance.py +207 -0
  46. admina/integrations/crewai/__init__.py +13 -0
  47. admina/integrations/crewai/callbacks.py +347 -0
  48. admina/integrations/langchain/__init__.py +13 -0
  49. admina/integrations/langchain/callbacks.py +341 -0
  50. admina/integrations/n8n/__init__.py +14 -0
  51. admina/integrations/openclaw/__init__.py +14 -0
  52. admina/plugins/__init__.py +49 -0
  53. admina/plugins/base.py +633 -0
  54. admina/plugins/builtin/__init__.py +14 -0
  55. admina/plugins/builtin/adapters/__init__.py +14 -0
  56. admina/plugins/builtin/adapters/ollama.py +120 -0
  57. admina/plugins/builtin/adapters/openai.py +138 -0
  58. admina/plugins/builtin/alerts/__init__.py +14 -0
  59. admina/plugins/builtin/alerts/log.py +66 -0
  60. admina/plugins/builtin/alerts/webhook.py +102 -0
  61. admina/plugins/builtin/auth/__init__.py +14 -0
  62. admina/plugins/builtin/auth/apikey.py +138 -0
  63. admina/plugins/builtin/compliance/__init__.py +14 -0
  64. admina/plugins/builtin/compliance/eu_ai_act.py +202 -0
  65. admina/plugins/builtin/connectors/__init__.py +14 -0
  66. admina/plugins/builtin/connectors/chromadb.py +137 -0
  67. admina/plugins/builtin/connectors/filesystem.py +111 -0
  68. admina/plugins/builtin/forensic/__init__.py +14 -0
  69. admina/plugins/builtin/forensic/filesystem.py +163 -0
  70. admina/plugins/builtin/forensic/minio.py +180 -0
  71. admina/plugins/builtin/guards/__init__.py +0 -0
  72. admina/plugins/builtin/guards/guardrailsai_guard.py +172 -0
  73. admina/plugins/builtin/pii/__init__.py +14 -0
  74. admina/plugins/builtin/pii/spacy_regex.py +160 -0
  75. admina/plugins/builtin/transports/__init__.py +14 -0
  76. admina/plugins/builtin/transports/http_rest.py +97 -0
  77. admina/plugins/builtin/transports/mcp.py +173 -0
  78. admina/plugins/registry.py +356 -0
  79. admina/proxy/__init__.py +15 -0
  80. admina/proxy/api/__init__.py +17 -0
  81. admina/proxy/api/dashboard.py +925 -0
  82. admina/proxy/api/integration.py +153 -0
  83. admina/proxy/config.py +214 -0
  84. admina/proxy/engine_bridge.py +306 -0
  85. admina/proxy/governance.py +232 -0
  86. admina/proxy/main.py +1484 -0
  87. admina/proxy/multi_upstream.py +156 -0
  88. admina/proxy/state.py +97 -0
  89. admina/py.typed +0 -0
  90. admina/sdk/__init__.py +34 -0
  91. admina/sdk/_compat.py +43 -0
  92. admina/sdk/compliance_kit.py +359 -0
  93. admina/sdk/governed_agent.py +391 -0
  94. admina/sdk/governed_data.py +434 -0
  95. admina/sdk/governed_model.py +241 -0
  96. admina_framework-0.9.0.dist-info/METADATA +575 -0
  97. admina_framework-0.9.0.dist-info/RECORD +102 -0
  98. admina_framework-0.9.0.dist-info/WHEEL +5 -0
  99. admina_framework-0.9.0.dist-info/entry_points.txt +2 -0
  100. admina_framework-0.9.0.dist-info/licenses/LICENSE +191 -0
  101. admina_framework-0.9.0.dist-info/licenses/NOTICE +16 -0
  102. admina_framework-0.9.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,314 @@
1
+ # Copyright © 2025–2026 Stefano Noferi & Admina contributors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Admina — cross-regulation control matrix (base).
16
+
17
+ A small, hand-curated mapping that shows which common operational
18
+ controls satisfy obligations across the three frameworks Admina
19
+ already covers in OSS: EU AI Act, NIS2, GDPR.
20
+
21
+ The matrix is **base coverage only** — twelve controls that show up
22
+ in essentially every operational compliance program. Full
23
+ sector-specific mappings (ISO 27001 ↔ NIS2 ↔ AI Act, NIST AI RMF ↔
24
+ ISO 42001, etc.) are out of scope for this release. Contributions
25
+ are welcome (see CONTRIBUTING.md).
26
+
27
+ Use cases:
28
+ - Show "if you implement X, you also satisfy obligations from N
29
+ different regulations" so the operator can plan once and report
30
+ multiple times.
31
+ - Drive a simple consolidated checklist in the dashboard.
32
+ - Power the JSON / CSV / Markdown export for stakeholders that
33
+ want to see all three regimes at a glance.
34
+ """
35
+
36
+ from __future__ import annotations
37
+
38
+ from typing import Any
39
+
40
+ # Each entry: control id → {title, description, mappings}
41
+ # `mappings` is keyed by regulation; value is a short list of
42
+ # article references AND a one-liner explaining the link.
43
+ CROSS_REGULATION_MATRIX: dict[str, dict[str, Any]] = {
44
+ "risk_assessment": {
45
+ "title": "Documented risk assessment",
46
+ "description": (
47
+ "Periodic identification, evaluation and prioritisation of "
48
+ "risks to the organisation's data, systems, and (where "
49
+ "applicable) AI outputs."
50
+ ),
51
+ "mappings": {
52
+ "eu_ai_act": [
53
+ {"ref": "Art. 9", "note": "Risk management system for high-risk AI"},
54
+ ],
55
+ "nis2": [
56
+ {"ref": "Art. 21(2)(a)", "note": "Risk analysis and security policy"},
57
+ ],
58
+ "gdpr": [
59
+ {"ref": "Art. 35", "note": "DPIA when processing is likely to result in high risk"},
60
+ {"ref": "Art. 32(1)", "note": "Security appropriate to risk"},
61
+ ],
62
+ },
63
+ },
64
+ "incident_handling": {
65
+ "title": "Incident detection, response, and reporting",
66
+ "description": (
67
+ "Documented incident handling: detection, classification, "
68
+ "internal response, post-mortem, regulator notification "
69
+ "where required."
70
+ ),
71
+ "mappings": {
72
+ "eu_ai_act": [
73
+ {"ref": "Art. 62", "note": "Reporting of serious incidents"},
74
+ ],
75
+ "nis2": [
76
+ {"ref": "Art. 21(2)(b)", "note": "Incident handling"},
77
+ {"ref": "Art. 23", "note": "24h early warning + 72h notification + 1-month report"},
78
+ ],
79
+ "gdpr": [
80
+ {"ref": "Art. 33", "note": "Personal data breach notification within 72h"},
81
+ {"ref": "Art. 34", "note": "Communication to data subjects"},
82
+ ],
83
+ },
84
+ },
85
+ "encryption_in_transit_and_at_rest": {
86
+ "title": "Encryption in transit and at rest",
87
+ "description": "TLS for transport, encryption-at-rest for stored data.",
88
+ "mappings": {
89
+ "eu_ai_act": [
90
+ {"ref": "Art. 15(4)", "note": "Cybersecurity of high-risk systems"},
91
+ ],
92
+ "nis2": [
93
+ {"ref": "Art. 21(2)(h)", "note": "Cryptography policies and procedures"},
94
+ ],
95
+ "gdpr": [
96
+ {"ref": "Art. 32(1)(a)", "note": "Pseudonymisation and encryption"},
97
+ ],
98
+ },
99
+ },
100
+ "access_control_mfa": {
101
+ "title": "Access control + MFA for privileged operations",
102
+ "description": (
103
+ "Role-based access control, MFA for admin and remote "
104
+ "access, joiner/mover/leaver process."
105
+ ),
106
+ "mappings": {
107
+ "eu_ai_act": [
108
+ {"ref": "Art. 15(4)", "note": "Cybersecurity measures"},
109
+ ],
110
+ "nis2": [
111
+ {"ref": "Art. 21(2)(i)", "note": "Access control + asset management"},
112
+ {"ref": "Art. 21(2)(j)", "note": "Multi-factor authentication"},
113
+ ],
114
+ "gdpr": [
115
+ {"ref": "Art. 32(1)(b)", "note": "Confidentiality and integrity"},
116
+ ],
117
+ },
118
+ },
119
+ "logging_and_audit_trail": {
120
+ "title": "Tamper-evident logging and audit trail",
121
+ "description": (
122
+ "Append-only event log with chain integrity (hashes or "
123
+ "signatures), enabling after-the-fact reconstruction of "
124
+ "decisions and access."
125
+ ),
126
+ "mappings": {
127
+ "eu_ai_act": [
128
+ {"ref": "Art. 12", "note": "Record-keeping for high-risk systems"},
129
+ ],
130
+ "nis2": [
131
+ {"ref": "Art. 21(2)(b)", "note": "Incident handling — supports investigation"},
132
+ ],
133
+ "gdpr": [
134
+ {"ref": "Art. 30", "note": "Records of processing activities"},
135
+ {"ref": "Art. 5(2)", "note": "Accountability principle"},
136
+ ],
137
+ },
138
+ },
139
+ "data_minimisation_and_retention": {
140
+ "title": "Data minimisation and defined retention",
141
+ "description": (
142
+ "Collect only what is necessary; delete or anonymise when "
143
+ "the retention period is reached."
144
+ ),
145
+ "mappings": {
146
+ "eu_ai_act": [
147
+ {"ref": "Art. 10(3)", "note": "Quality and relevance of training/validation data"},
148
+ ],
149
+ "nis2": [], # no direct NIS2 obligation
150
+ "gdpr": [
151
+ {"ref": "Art. 5(1)(c)", "note": "Data minimisation"},
152
+ {"ref": "Art. 5(1)(e)", "note": "Storage limitation"},
153
+ ],
154
+ },
155
+ },
156
+ "third_party_risk_management": {
157
+ "title": "Third-party / supply-chain risk management",
158
+ "description": (
159
+ "Inventory of suppliers and processors, risk assessment, "
160
+ "contractual security clauses, incident-notification clauses."
161
+ ),
162
+ "mappings": {
163
+ "eu_ai_act": [
164
+ {"ref": "Art. 25", "note": "Obligations along the AI value chain"},
165
+ ],
166
+ "nis2": [
167
+ {"ref": "Art. 21(2)(d)", "note": "Supply chain security"},
168
+ ],
169
+ "gdpr": [
170
+ {"ref": "Art. 28", "note": "Processor contractual obligations"},
171
+ {"ref": "Art. 44-49", "note": "International transfers"},
172
+ ],
173
+ },
174
+ },
175
+ "human_oversight": {
176
+ "title": "Human oversight of automated decisions",
177
+ "description": (
178
+ "A human reviewer can intervene, override, or audit "
179
+ "decisions made by an automated system."
180
+ ),
181
+ "mappings": {
182
+ "eu_ai_act": [
183
+ {"ref": "Art. 14", "note": "Human oversight of high-risk AI"},
184
+ ],
185
+ "nis2": [],
186
+ "gdpr": [
187
+ {"ref": "Art. 22", "note": "Right not to be subject to solely automated decisions"},
188
+ ],
189
+ },
190
+ },
191
+ "transparency_and_information": {
192
+ "title": "Transparency to end users / data subjects",
193
+ "description": (
194
+ "Users and data subjects are informed about purpose, "
195
+ "logic, and consequences of processing — including AI "
196
+ "interactions."
197
+ ),
198
+ "mappings": {
199
+ "eu_ai_act": [
200
+ {"ref": "Art. 13", "note": "Transparency for high-risk AI"},
201
+ {"ref": "Art. 50", "note": "Transparency for chatbots / synthetic content"},
202
+ ],
203
+ "nis2": [],
204
+ "gdpr": [
205
+ {"ref": "Art. 12-14", "note": "Information to data subjects"},
206
+ ],
207
+ },
208
+ },
209
+ "training_and_awareness": {
210
+ "title": "Staff training and security awareness",
211
+ "description": "Annual training, phishing drills, role-specific awareness.",
212
+ "mappings": {
213
+ "eu_ai_act": [
214
+ {"ref": "Art. 4", "note": "AI literacy"},
215
+ ],
216
+ "nis2": [
217
+ {"ref": "Art. 21(2)(g)", "note": "Cyber hygiene + cybersecurity training"},
218
+ ],
219
+ "gdpr": [
220
+ {"ref": "Art. 39(1)(b)", "note": "DPO awareness-raising / training"},
221
+ ],
222
+ },
223
+ },
224
+ "business_continuity": {
225
+ "title": "Business continuity and disaster recovery",
226
+ "description": ("Backup strategy, disaster recovery plan, regular tests."),
227
+ "mappings": {
228
+ "eu_ai_act": [
229
+ {"ref": "Art. 15(4)", "note": "Resilience of high-risk AI"},
230
+ ],
231
+ "nis2": [
232
+ {
233
+ "ref": "Art. 21(2)(c)",
234
+ "note": "Business continuity, backup, DR, crisis management",
235
+ },
236
+ ],
237
+ "gdpr": [
238
+ {
239
+ "ref": "Art. 32(1)(c)",
240
+ "note": "Ability to restore availability and access in a timely manner",
241
+ },
242
+ ],
243
+ },
244
+ },
245
+ "documentation_and_accountability": {
246
+ "title": "Documentation of decisions and accountability",
247
+ "description": (
248
+ "Documented evidence that compliance measures are in place and operate as intended."
249
+ ),
250
+ "mappings": {
251
+ "eu_ai_act": [
252
+ {"ref": "Art. 11", "note": "Technical documentation for high-risk systems"},
253
+ ],
254
+ "nis2": [
255
+ {"ref": "Art. 21(2)(f)", "note": "Effectiveness assessment"},
256
+ ],
257
+ "gdpr": [
258
+ {"ref": "Art. 5(2)", "note": "Accountability principle"},
259
+ {"ref": "Art. 24", "note": "Responsibility of the controller"},
260
+ ],
261
+ },
262
+ },
263
+ }
264
+
265
+
266
+ REGULATIONS: tuple[str, ...] = ("eu_ai_act", "nis2", "gdpr")
267
+
268
+
269
+ def coverage_summary() -> dict[str, Any]:
270
+ """Aggregate counts that can drive a compact dashboard widget.
271
+
272
+ Returns the total number of controls and, for each regulation,
273
+ how many controls touch it (i.e. have at least one mapping).
274
+ """
275
+ total = len(CROSS_REGULATION_MATRIX)
276
+ by_reg: dict[str, int] = {r: 0 for r in REGULATIONS}
277
+ for ctrl in CROSS_REGULATION_MATRIX.values():
278
+ for reg in REGULATIONS:
279
+ if ctrl["mappings"].get(reg):
280
+ by_reg[reg] += 1
281
+ return {
282
+ "total_controls": total,
283
+ "regulations": list(REGULATIONS),
284
+ "controls_per_regulation": by_reg,
285
+ }
286
+
287
+
288
+ def to_markdown() -> str:
289
+ """Render the matrix as a stand-alone Markdown table.
290
+
291
+ Used by the reporting export endpoint when the operator picks
292
+ `format=markdown`. The frontend can show the same data as an
293
+ HTML table without re-implementing it.
294
+ """
295
+ lines = [
296
+ "# Cross-regulation control matrix",
297
+ "",
298
+ "Base coverage of operational controls across EU AI Act, NIS2, and GDPR.",
299
+ "",
300
+ "| Control | EU AI Act | NIS2 | GDPR |",
301
+ "|---|---|---|---|",
302
+ ]
303
+ for ctrl_id, ctrl in CROSS_REGULATION_MATRIX.items():
304
+ cells = []
305
+ for reg in REGULATIONS:
306
+ refs = ctrl["mappings"].get(reg) or []
307
+ if refs:
308
+ cells.append(", ".join(r["ref"] for r in refs))
309
+ else:
310
+ cells.append("—")
311
+ lines.append(
312
+ f"| **{ctrl['title']}**<br/>_{ctrl_id}_ | {cells[0]} | {cells[1]} | {cells[2]} |"
313
+ )
314
+ return "\n".join(lines) + "\n"
@@ -0,0 +1,367 @@
1
+ # Copyright © 2025–2026 Stefano Noferi & Admina contributors
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ Admina — EU AI Act Compliance Engine — Compliance domain
17
+ Automated risk classification, gap analysis, and compliance reporting.
18
+ """
19
+
20
+ import logging
21
+ from datetime import UTC, datetime
22
+
23
+ logger = logging.getLogger("admina.eu_ai_act")
24
+
25
+ # ── EU AI Act application timeline (Art. 113, Regulation 2024/1689) ─────────
26
+ # Reflects the "AI Act Omnibus" agreement reached by Council and Parliament
27
+ # on 7 May 2026 (Omnibus VII), which postponed several high-risk deadlines
28
+ # and added a new Art. 5 prohibition (NCII / synthetic CSAM).
29
+ #
30
+ # Sources:
31
+ # - Reg. (EU) 2024/1689 (original AI Act)
32
+ # - Council/Parliament press release 2026-05-07 (Omnibus VII agreement)
33
+ EU_AI_ACT_DEADLINES: dict[str, str] = {
34
+ # Art. 5 prohibitions — already in force
35
+ "prohibitions": "2025-02-02",
36
+ # GPAI obligations Art. 50-55 — already in force
37
+ "gpai_obligations": "2025-08-02",
38
+ # Art. 50 transparency for synthetic content (watermarking).
39
+ # Omnibus reduced the grace period 6m → 3m; new effective date below.
40
+ "transparency_synthetic_content": "2026-12-02",
41
+ # NEW Art. 5 prohibition: non-consensual intimate imagery + synthetic CSAM
42
+ "prohibitions_ncii_csam": "2026-12-02",
43
+ # Annex III high-risk (employment, education, biometrics, scoring, …)
44
+ # Postponed from 2 Aug 2026 → 2 Dec 2027 by Omnibus VII.
45
+ "high_risk_annex_iii": "2027-12-02",
46
+ # National AI regulatory sandboxes (Art. 57)
47
+ # Postponed from 2 Aug 2026 → 2 Aug 2027 by Omnibus VII.
48
+ "national_sandboxes": "2027-08-02",
49
+ # Annex I high-risk (medical devices, toys, regulated products)
50
+ # Postponed from 2 Aug 2027 → 2 Aug 2028 by Omnibus VII.
51
+ "high_risk_annex_i": "2028-08-02",
52
+ # Latest applicable date — overall "full application" reference
53
+ "full_application": "2028-08-02",
54
+ }
55
+
56
+ # Primary deadline used in dashboards / countdowns / single-value APIs.
57
+ # Annex III is the most relevant for the typical Admina user (it covers
58
+ # employment, scoring, education, biometrics — the bulk of operational AI).
59
+ EU_AI_ACT_ENFORCEMENT_DEADLINE: str = EU_AI_ACT_DEADLINES["high_risk_annex_iii"]
60
+
61
+
62
+ # ── Risk Classification Keywords ─────────────────────────────────────────────
63
+ # Source: EU AI Act Annex III + Art. 5 prohibited practices (Reg. 2024/1689,
64
+ # as amended by the Omnibus VII agreement of 7 May 2026).
65
+ # Update these when the Commission publishes delegated acts extending Annex III.
66
+
67
+ UNACCEPTABLE_RISK_KEYWORDS = [
68
+ "social scoring",
69
+ "social credit",
70
+ "real-time biometric",
71
+ "mass surveillance",
72
+ "subliminal manipulation",
73
+ # Added by Omnibus VII (effective 2 Dec 2026):
74
+ "non-consensual intimate imagery",
75
+ "non-consensual deepfake",
76
+ "synthetic csam",
77
+ "ai-generated child sexual abuse",
78
+ "deepfake nudification",
79
+ "nudifier",
80
+ ]
81
+
82
+ HIGH_RISK_KEYWORDS = [
83
+ "credit scor",
84
+ "recruitment",
85
+ "hiring",
86
+ "law enforcement",
87
+ "critical infrastructure",
88
+ "healthcare",
89
+ "medical",
90
+ "education",
91
+ "migration",
92
+ "border",
93
+ "judicial",
94
+ "biometric",
95
+ "financial",
96
+ "trading",
97
+ "insurance",
98
+ ]
99
+
100
+ HIGH_RISK_SENSITIVE_DATA = ["health", "biometric", "financial", "criminal", "genetic"]
101
+
102
+ LIMITED_RISK_KEYWORDS = [
103
+ "chatbot",
104
+ "conversational",
105
+ "content generation",
106
+ "emotion recognition",
107
+ "deepfake",
108
+ "synthetic media",
109
+ ]
110
+
111
+
112
+ # EU AI Act Risk Categories
113
+ RISK_CATEGORIES = {
114
+ "unacceptable": {
115
+ "level": 4,
116
+ "description": "Prohibited AI practices",
117
+ "examples": [
118
+ "social scoring",
119
+ "real-time biometric identification",
120
+ "manipulation of vulnerable groups",
121
+ "non-consensual intimate imagery / synthetic CSAM (Omnibus VII, effective 2 Dec 2026)",
122
+ ],
123
+ "action": "PROHIBITED — Must not deploy",
124
+ },
125
+ "high": {
126
+ "level": 3,
127
+ "description": "High-risk AI systems requiring conformity assessment",
128
+ "examples": [
129
+ "credit scoring",
130
+ "recruitment",
131
+ "law enforcement",
132
+ "critical infrastructure",
133
+ "healthcare diagnostics",
134
+ ],
135
+ "action": "Requires conformity assessment, logging, human oversight",
136
+ },
137
+ "limited": {
138
+ "level": 2,
139
+ "description": "Limited risk with transparency obligations",
140
+ "examples": ["chatbots", "emotion recognition", "deepfakes", "content generation"],
141
+ "action": "Must inform users they are interacting with AI",
142
+ },
143
+ "minimal": {
144
+ "level": 1,
145
+ "description": "Minimal or no risk",
146
+ "examples": ["spam filters", "inventory management", "video game AI"],
147
+ "action": "No specific obligations, voluntary codes of conduct",
148
+ },
149
+ }
150
+
151
+ # Compliance requirements for high-risk systems
152
+ HIGH_RISK_REQUIREMENTS = {
153
+ "risk_management": {
154
+ "name": "Risk Management System",
155
+ "article": "Art. 9",
156
+ "checks": [
157
+ "Documented risk management process",
158
+ "Risk identification and analysis",
159
+ "Risk mitigation measures implemented",
160
+ "Residual risk assessment completed",
161
+ ],
162
+ },
163
+ "data_governance": {
164
+ "name": "Data Governance",
165
+ "article": "Art. 10",
166
+ "checks": [
167
+ "Training data quality measures",
168
+ "Data bias examination",
169
+ "Data provenance documentation",
170
+ "Privacy impact assessment",
171
+ ],
172
+ },
173
+ "technical_documentation": {
174
+ "name": "Technical Documentation",
175
+ "article": "Art. 11",
176
+ "checks": [
177
+ "System description and purpose",
178
+ "Development process documentation",
179
+ "Performance metrics documented",
180
+ "Limitations and risks documented",
181
+ ],
182
+ },
183
+ "record_keeping": {
184
+ "name": "Record Keeping / Logging",
185
+ "article": "Art. 12",
186
+ "checks": [
187
+ "Automatic event logging enabled",
188
+ "Log retention period defined (min 6 months)",
189
+ "Logs include traceability data",
190
+ "Tamper-proof logging mechanism",
191
+ ],
192
+ },
193
+ "transparency": {
194
+ "name": "Transparency",
195
+ "article": "Art. 13",
196
+ "checks": [
197
+ "Instructions for use provided",
198
+ "Capabilities and limitations documented",
199
+ "Human oversight measures described",
200
+ "Performance characteristics disclosed",
201
+ ],
202
+ },
203
+ "human_oversight": {
204
+ "name": "Human Oversight",
205
+ "article": "Art. 14",
206
+ "checks": [
207
+ "Human oversight interface exists",
208
+ "Override mechanism available",
209
+ "Escalation procedures defined",
210
+ "Monitoring dashboards operational",
211
+ ],
212
+ },
213
+ "accuracy_robustness": {
214
+ "name": "Accuracy, Robustness, Cybersecurity",
215
+ "article": "Art. 15",
216
+ "checks": [
217
+ "Accuracy metrics defined and monitored",
218
+ "Robustness testing performed",
219
+ "Cybersecurity measures implemented",
220
+ "Adversarial attack resistance tested",
221
+ ],
222
+ },
223
+ }
224
+
225
+
226
+ class EUAIActCompliance:
227
+ """
228
+ Automated EU AI Act compliance checking and reporting.
229
+ """
230
+
231
+ def __init__(self):
232
+ self.assessments: list[dict] = []
233
+
234
+ def classify_risk(self, system_description: str, use_case: str, data_types: list[str]) -> dict:
235
+ """
236
+ Classify an AI system's risk level under the EU AI Act.
237
+ """
238
+ description_lower = system_description.lower()
239
+ use_case_lower = use_case.lower()
240
+
241
+ # Check for unacceptable risk indicators
242
+ if any(
243
+ kw in description_lower or kw in use_case_lower for kw in UNACCEPTABLE_RISK_KEYWORDS
244
+ ):
245
+ return {
246
+ "risk_category": "unacceptable",
247
+ **RISK_CATEGORIES["unacceptable"],
248
+ }
249
+
250
+ # Check for high-risk indicators
251
+ high_risk_score = 0
252
+ if any(kw in description_lower or kw in use_case_lower for kw in HIGH_RISK_KEYWORDS):
253
+ high_risk_score += 2
254
+ if any(dt in HIGH_RISK_SENSITIVE_DATA for dt in [d.lower() for d in data_types]):
255
+ high_risk_score += 1
256
+
257
+ if high_risk_score >= 2:
258
+ return {
259
+ "risk_category": "high",
260
+ **RISK_CATEGORIES["high"],
261
+ }
262
+
263
+ # Check for limited risk
264
+ if any(kw in description_lower or kw in use_case_lower for kw in LIMITED_RISK_KEYWORDS):
265
+ return {
266
+ "risk_category": "limited",
267
+ **RISK_CATEGORIES["limited"],
268
+ }
269
+
270
+ return {
271
+ "risk_category": "minimal",
272
+ **RISK_CATEGORIES["minimal"],
273
+ }
274
+
275
+ def gap_analysis(self, risk_category: str, current_compliance: dict[str, list[bool]]) -> dict:
276
+ """
277
+ Perform gap analysis for a high-risk AI system.
278
+ current_compliance: {requirement_key: [True/False for each check]}
279
+ """
280
+ if risk_category not in ("high", "unacceptable"):
281
+ return {
282
+ "applicable": False,
283
+ "message": f"Full gap analysis not required for {risk_category}-risk systems",
284
+ }
285
+
286
+ gaps = []
287
+ total_checks = 0
288
+ passed_checks = 0
289
+
290
+ for req_key, req_info in HIGH_RISK_REQUIREMENTS.items():
291
+ checks = current_compliance.get(req_key, [False] * len(req_info["checks"]))
292
+ for i, (check_desc, is_met) in enumerate(zip(req_info["checks"], checks)):
293
+ total_checks += 1
294
+ if is_met:
295
+ passed_checks += 1
296
+ else:
297
+ gaps.append(
298
+ {
299
+ "requirement": req_info["name"],
300
+ "article": req_info["article"],
301
+ "check": check_desc,
302
+ "status": "NOT_MET",
303
+ }
304
+ )
305
+
306
+ compliance_score = round(passed_checks / max(total_checks, 1) * 100, 1)
307
+
308
+ result = {
309
+ "applicable": True,
310
+ "compliance_score": compliance_score,
311
+ "total_checks": total_checks,
312
+ "passed_checks": passed_checks,
313
+ "gaps": gaps,
314
+ "gap_count": len(gaps),
315
+ "status": "COMPLIANT" if compliance_score == 100 else "GAPS_FOUND",
316
+ "enforcement_deadline": EU_AI_ACT_ENFORCEMENT_DEADLINE,
317
+ "assessed_at": datetime.now(UTC).isoformat(),
318
+ }
319
+
320
+ self.assessments.append(result)
321
+ return result
322
+
323
+ def generate_report(self, system_name: str, classification: dict, gap_result: dict) -> dict:
324
+ """Generate a compliance report summary."""
325
+ return {
326
+ "report_title": f"EU AI Act Compliance Report — {system_name}",
327
+ "generated_at": datetime.now(UTC).isoformat(),
328
+ "system_name": system_name,
329
+ "risk_classification": classification,
330
+ "gap_analysis": gap_result,
331
+ "recommendations": self._generate_recommendations(gap_result),
332
+ "next_steps": [
333
+ "Address all identified gaps before enforcement deadline",
334
+ "Schedule conformity assessment if high-risk",
335
+ "Establish ongoing monitoring and review process",
336
+ "Appoint AI compliance officer",
337
+ ],
338
+ }
339
+
340
+ def _generate_recommendations(self, gap_result: dict) -> list[str]:
341
+ recs = []
342
+ if not gap_result.get("applicable"):
343
+ return ["Continue voluntary best practices"]
344
+
345
+ gap_areas = set(g["requirement"] for g in gap_result.get("gaps", []))
346
+ if "Record Keeping / Logging" in gap_areas:
347
+ recs.append(
348
+ "PRIORITY: Enable Admina Forensic Black Box for tamper-proof logging (Art. 12)"
349
+ )
350
+ if "Human Oversight" in gap_areas:
351
+ recs.append(
352
+ "PRIORITY: Configure escalation policies and human-in-the-loop workflows (Art. 14)"
353
+ )
354
+ if "Accuracy, Robustness, Cybersecurity" in gap_areas:
355
+ recs.append("Enable Anti-Injection Firewall and Loop Breaker for robustness (Art. 15)")
356
+ if "Transparency" in gap_areas:
357
+ recs.append("Document agent capabilities and limitations in system registry (Art. 13)")
358
+ if "Data Governance" in gap_areas:
359
+ recs.append("Enable PII Redaction and configure data governance policies (Art. 10)")
360
+
361
+ return recs if recs else ["All requirements met — maintain compliance posture"]
362
+
363
+ def get_stats(self) -> dict:
364
+ return {
365
+ "total_assessments": len(self.assessments),
366
+ "enforcement_deadline": EU_AI_ACT_ENFORCEMENT_DEADLINE,
367
+ }