mirror of
https://github.com/Shiva108/ai-llm-red-team-handbook.git
synced 2026-05-15 21:18:00 +02:00
b3d3bac51f
- Extracted all code examples from handbook chapters - Organized into 15 attack categories - Created shared utilities (api_client, validators, logging, constants) - Added workflow orchestration scripts - Implemented install.sh for easy setup - Renamed all scripts to descriptive functional names - Added comprehensive README and documentation - Included pytest test suite and configuration
115 lines
3.2 KiB
Python
115 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
40.9.2 Risk Scoring Automation
|
|
|
|
Source: Chapter_40_Compliance_and_Standards
|
|
Category: compliance
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
class RiskLevel(Enum):
|
|
LOW = 1
|
|
MEDIUM = 2
|
|
HIGH = 3
|
|
CRITICAL = 4
|
|
|
|
@dataclass
|
|
class AISystemRiskProfile:
|
|
"""EU AI Act risk classification engine."""
|
|
|
|
# System characteristics
|
|
affects_safety: bool
|
|
affects_rights: bool
|
|
affects_children: bool
|
|
affects_biometrics: bool
|
|
affects_critical_infra: bool
|
|
affects_law_enforcement: bool
|
|
affects_employment: bool
|
|
affects_education: bool
|
|
|
|
def calculate_eu_risk_class(self) -> str:
|
|
"""
|
|
Determines EU AI Act risk classification.
|
|
Article 6: Prohibited
|
|
Article 7: High Risk
|
|
Article 69: Limited Risk
|
|
"""
|
|
|
|
# Prohibited AI (Article 5)
|
|
prohibited_conditions = [
|
|
self.affects_children and self.affects_biometrics,
|
|
# Add other prohibited conditions
|
|
]
|
|
|
|
if any(prohibited_conditions):
|
|
return "PROHIBITED - Deploy Forbidden"
|
|
|
|
# High Risk (Article 6 & Annex III)
|
|
high_risk_conditions = [
|
|
self.affects_critical_infra,
|
|
self.affects_law_enforcement,
|
|
self.affects_employment,
|
|
self.affects_education and self.affects_rights,
|
|
self.affects_biometrics,
|
|
]
|
|
|
|
if any(high_risk_conditions):
|
|
return "HIGH RISK - Mandatory Compliance (Art 8-15)"
|
|
|
|
# Limited Risk
|
|
if self.affects_rights:
|
|
return "LIMITED RISK - Transparency Required (Art 52)"
|
|
|
|
return "MINIMAL RISK - No specific obligations"
|
|
|
|
def required_controls(self) -> List[str]:
|
|
"""Returns list of mandatory controls based on risk class."""
|
|
risk_class = self.calculate_eu_risk_class()
|
|
|
|
if "HIGH RISK" in risk_class:
|
|
return [
|
|
"Risk Management System (Art 9)",
|
|
"Data Governance (Art 10)",
|
|
"Technical Documentation (Art 11)",
|
|
"Record Keeping (Art 12)",
|
|
"Transparency to Users (Art 13)",
|
|
"Human Oversight (Art 14)",
|
|
"Accuracy/Robustness/Cybersecurity (Art 15)"
|
|
]
|
|
elif "LIMITED RISK" in risk_class:
|
|
return ["Transparency Obligation (Art 52)"]
|
|
else:
|
|
return ["Best Practices (Voluntary)"]
|
|
|
|
# Example: Corporate HR Hiring AI
|
|
hr_system = AISystemRiskProfile(
|
|
affects_safety=False,
|
|
affects_rights=True,
|
|
affects_children=False,
|
|
affects_biometrics=False,
|
|
affects_critical_infra=False,
|
|
affects_law_enforcement=False,
|
|
affects_employment=True, # HR/Hiring = High Risk per Annex III
|
|
affects_education=False
|
|
)
|
|
|
|
print(f"Classification: {hr_system.calculate_eu_risk_class()}")
|
|
print(f"Required Controls: {hr_system.required_controls()}")
|
|
|
|
|
|
def main():
|
|
"""Command-line interface."""
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
|
|
args = parser.parse_args()
|
|
|
|
# TODO: Add main execution logic
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main() |