|
| 1 | +"""Maps Airlock data to RBI FREE-AI 7 Sutras and 26 recommendations.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import logging |
| 6 | +from typing import Any |
| 7 | + |
| 8 | +from airlock.compliance.incident import IncidentStore |
| 9 | +from airlock.compliance.inventory import AgentInventory |
| 10 | + |
| 11 | +logger = logging.getLogger(__name__) |
| 12 | + |
| 13 | +# FREE-AI Sutras |
| 14 | +SUTRAS: dict[str, str] = { |
| 15 | + "sutra_1": "Governance & Oversight", |
| 16 | + "sutra_2": "Risk Management", |
| 17 | + "sutra_3": "Data Privacy & Security", |
| 18 | + "sutra_4": "Transparency & Explainability", |
| 19 | + "sutra_5": "Fairness & Non-discrimination", |
| 20 | + "sutra_6": "Accountability & Audit", |
| 21 | + "sutra_7": "Consumer Protection", |
| 22 | +} |
| 23 | + |
| 24 | +# Recommendation -> Airlock feature mapping |
| 25 | +RECOMMENDATION_MAP: dict[str, dict[str, str]] = { |
| 26 | + "rec_13": { |
| 27 | + "title": "Incident Reporting", |
| 28 | + "airlock_feature": "incident_tracking", |
| 29 | + "sutra": "sutra_2", |
| 30 | + }, |
| 31 | + "rec_14": { |
| 32 | + "title": "AI Model Inventory", |
| 33 | + "airlock_feature": "agent_inventory", |
| 34 | + "sutra": "sutra_1", |
| 35 | + }, |
| 36 | + "rec_15": { |
| 37 | + "title": "Auditor Assessment by Risk Profile", |
| 38 | + "airlock_feature": "risk_classification", |
| 39 | + "sutra": "sutra_2", |
| 40 | + }, |
| 41 | + "rec_16": { |
| 42 | + "title": "AI Disclosures in Annual Reports", |
| 43 | + "airlock_feature": "compliance_reports", |
| 44 | + "sutra": "sutra_4", |
| 45 | + }, |
| 46 | + "rec_19": { |
| 47 | + "title": "Internal Audit Proportional to Risk", |
| 48 | + "airlock_feature": "audit_trail", |
| 49 | + "sutra": "sutra_6", |
| 50 | + }, |
| 51 | + "rec_20": { |
| 52 | + "title": "Red Teaming", |
| 53 | + "airlock_feature": "adversarial_testing", |
| 54 | + "sutra": "sutra_2", |
| 55 | + }, |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +class FreeAIMapper: |
| 60 | + """Map Airlock compliance state to FREE-AI recommendations.""" |
| 61 | + |
| 62 | + def map_compliance_status( |
| 63 | + self, |
| 64 | + inventory: AgentInventory, |
| 65 | + incident_store: IncidentStore, |
| 66 | + ) -> dict[str, dict[str, Any]]: |
| 67 | + """Map current Airlock state to FREE-AI recommendation compliance status. |
| 68 | +
|
| 69 | + Returns a dict keyed by recommendation ID with compliance details. |
| 70 | + """ |
| 71 | + result: dict[str, dict[str, Any]] = {} |
| 72 | + for rec_id, rec_info in RECOMMENDATION_MAP.items(): |
| 73 | + result[rec_id] = self.get_recommendation_status( |
| 74 | + rec_id, inventory, incident_store |
| 75 | + ) |
| 76 | + return result |
| 77 | + |
| 78 | + def get_recommendation_status( |
| 79 | + self, |
| 80 | + rec_id: str, |
| 81 | + inventory: AgentInventory, |
| 82 | + incident_store: IncidentStore, |
| 83 | + ) -> dict[str, Any]: |
| 84 | + """Get compliance status for a specific recommendation.""" |
| 85 | + rec_info = RECOMMENDATION_MAP.get(rec_id) |
| 86 | + if rec_info is None: |
| 87 | + return { |
| 88 | + "status": "unknown", |
| 89 | + "title": "Unknown Recommendation", |
| 90 | + "details": f"Recommendation {rec_id} not mapped", |
| 91 | + } |
| 92 | + |
| 93 | + feature = rec_info["airlock_feature"] |
| 94 | + sutra = rec_info["sutra"] |
| 95 | + title = rec_info["title"] |
| 96 | + |
| 97 | + status = self._assess_feature_status(feature, inventory, incident_store) |
| 98 | + |
| 99 | + return { |
| 100 | + "rec_id": rec_id, |
| 101 | + "title": title, |
| 102 | + "sutra": sutra, |
| 103 | + "sutra_name": SUTRAS.get(sutra, "Unknown"), |
| 104 | + "airlock_feature": feature, |
| 105 | + "status": status, |
| 106 | + } |
| 107 | + |
| 108 | + def get_sutra_summary( |
| 109 | + self, |
| 110 | + inventory: AgentInventory, |
| 111 | + incident_store: IncidentStore, |
| 112 | + ) -> dict[str, dict[str, Any]]: |
| 113 | + """Get compliance summary grouped by Sutra.""" |
| 114 | + full_mapping = self.map_compliance_status(inventory, incident_store) |
| 115 | + |
| 116 | + sutra_summary: dict[str, dict[str, Any]] = {} |
| 117 | + for sutra_id, sutra_name in SUTRAS.items(): |
| 118 | + recs = [ |
| 119 | + v |
| 120 | + for v in full_mapping.values() |
| 121 | + if v.get("sutra") == sutra_id |
| 122 | + ] |
| 123 | + compliant = sum(1 for r in recs if r.get("status") == "compliant") |
| 124 | + total = len(recs) |
| 125 | + sutra_summary[sutra_id] = { |
| 126 | + "name": sutra_name, |
| 127 | + "recommendations": total, |
| 128 | + "compliant": compliant, |
| 129 | + "status": "compliant" if compliant == total and total > 0 else "partial", |
| 130 | + } |
| 131 | + return sutra_summary |
| 132 | + |
| 133 | + def _assess_feature_status( |
| 134 | + self, |
| 135 | + feature: str, |
| 136 | + inventory: AgentInventory, |
| 137 | + incident_store: IncidentStore, |
| 138 | + ) -> str: |
| 139 | + """Assess whether a specific Airlock feature meets compliance.""" |
| 140 | + if feature == "agent_inventory": |
| 141 | + # Compliant if at least one agent is registered |
| 142 | + return "compliant" if len(inventory) > 0 else "not_implemented" |
| 143 | + |
| 144 | + if feature == "risk_classification": |
| 145 | + # Compliant if agents have been assessed |
| 146 | + entries = inventory.list_all() |
| 147 | + if not entries: |
| 148 | + return "not_implemented" |
| 149 | + assessed = sum(1 for e in entries if e.last_assessed_at is not None) |
| 150 | + return "compliant" if assessed > 0 else "partial" |
| 151 | + |
| 152 | + if feature == "incident_tracking": |
| 153 | + # Feature is available (store exists), compliant |
| 154 | + return "compliant" |
| 155 | + |
| 156 | + if feature == "compliance_reports": |
| 157 | + # Feature is available (generator exists), compliant |
| 158 | + return "compliant" |
| 159 | + |
| 160 | + if feature == "audit_trail": |
| 161 | + # Audit trail is always available in Airlock |
| 162 | + return "compliant" |
| 163 | + |
| 164 | + if feature == "adversarial_testing": |
| 165 | + # Red teaming is a process, not a feature -- mark as partial |
| 166 | + return "partial" |
| 167 | + |
| 168 | + return "unknown" |
0 commit comments