mirror of
https://github.com/Shiva108/ai-llm-red-team-handbook.git
synced 2026-05-14 12:48:16 +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
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
40.4.2 `log_auditor.py`
|
|
|
|
Source: Chapter_40_Compliance_and_Standards
|
|
Category: compliance
|
|
"""
|
|
|
|
import re
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
class LogComplianceAuditor:
|
|
def __init__(self, log_data: list):
|
|
self.logs = log_data
|
|
# Regex patterns for required fields in a structured log (JSON)
|
|
self.requirements = {
|
|
"Timestamp": r'"timestamp":',
|
|
"Model_ID": r'"model_id":',
|
|
"Input_Hash": r'"input_hash":', # Checking for hash, not raw data (privacy)
|
|
"Safety_Score": r'"safety_score":',
|
|
"Latency": r'"latency_ms":'
|
|
}
|
|
|
|
def audit(self):
|
|
print(f"[*] Auditing {len(self.logs)} log entries for EU AI Act Art. 12 Compliance...")
|
|
for i, log_entry in enumerate(self.logs):
|
|
missing = []
|
|
for field, pattern in self.requirements.items():
|
|
if not re.search(pattern, log_entry):
|
|
missing.append(field)
|
|
|
|
if missing:
|
|
print(f"[FAIL] Line {i+1}: Missing fields {missing} -> NON-COMPLIANT")
|
|
else:
|
|
print(f"[PASS] Line {i+1}: Fully Compliant")
|
|
|
|
# Usage
|
|
logs = [
|
|
'{"timestamp": "2024-01-01T12:00:00", "model_id": "gpt-4", "input_hash": "abc", "safety_score": 0.1, "latency_ms": 500}',
|
|
'{"timestamp": "2024-01-01T12:01:00", "error": "timeout"}' # This will fail
|
|
]
|
|
auditor = LogComplianceAuditor(logs)
|
|
auditor.audit()
|
|
|
|
|
|
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() |