Lesson 6 of 13
Accountability
When an AI system hallucinates, leaks sensitive data, or makes a discriminatory decision, autonomous software cannot stand in court. Understand the Shared Responsibility Model across providers, developers, and deployers, alongside immutable cryptographic audit trails.
Immutable AI Audit Trail Logger with SHA-256 Hash Chaining
Immutable AI Audit Trail Logger with SHA-256 Hash Chaining
# Immutable AI Audit Trail: Cryptographic Hash Chaining for Legal Defensibility
import hashlib
import json
import time
class AIAuditTrailLogger:
def __init__(self):
self.chain = []
def log_inference_event(self, user_id: str, model_id: str, prompt: str, output: str):
prev_hash = self.chain[-1]["block_hash"] if self.chain else "GENESIS_HASH"
event_record = {
"index": len(self.chain) + 1,
"timestamp": int(time.time()),
"user_id": user_id,
"model_id": model_id,
"prompt_sha256": hashlib.sha256(prompt.encode()).hexdigest(),
"output_sha256": hashlib.sha256(output.encode()).hexdigest(),
"previous_hash": prev_hash
}
record_bytes = json.dumps(event_record, sort_keys=True).encode()
event_record["block_hash"] = hashlib.sha256(record_bytes).hexdigest()
self.chain.append(event_record)
print(f"Logged Audit Event #{event_record['index']} (Hash: {event_record['block_hash'][:12]}...)")
logger = AIAuditTrailLogger()
logger.log_inference_event("user_849", "gpt-4o", "Analyze loan eligibility for applicant #991", "Approved at Tier-2")
logger.log_inference_event("user_102", "gpt-4o", "Extract NDA indemnity terms", "Indemnity capped at 2x fees")
print("\nTotal Verified Audit Records:", len(logger.chain))Diagram
Loading diagram…
Accountability Diagram
The Shared Responsibility Model in Generative AI
- Foundation Model Provider (OpenAI, Anthropic): Accountable for pretraining data safety, foundational alignment (RLHF), and API platform uptime
- Application Developer: Accountable for prompt injection guardrails, RAG document veracity, API secret isolation, and output sanitization
- Enterprise Deployer: Accountable for defining employee usage policies, compliance monitoring, and customer recourse channels
- Human End-User: Accountable for exercising critical verification and never blindly trusting raw synthetic outputs
Quick Q&A
Key Takeaways
- When an AI system hallucinates, leaks sensitive data, or makes a discriminatory decision, autonomous software cannot stand in court.
- Foundation Model Provider (OpenAI, Anthropic): Accountable for pretraining data safety, foundational alignment (RLHF), and API platform uptime
- Application Developer: Accountable for prompt injection guardrails, RAG document veracity, API secret isolation, and output sanitization
- Enterprise Deployer: Accountable for defining employee usage policies, compliance monitoring, and customer recourse channels
Finished this lesson?
0 of 13 in Module 12