Best Practices

Responsible Deployment

Implement practical guidelines for deploying AI ethically and maintaining ongoing oversight.

The AI Development Lifecycle

Ethical considerations span the entire lifecycle:

  1. Problem definition: Should we even build this?
  2. Data collection: Is data obtained ethically?
  3. Model development: Are we testing for bias?
  4. Evaluation: Are we measuring what matters?
  5. Deployment: Who is affected?
  6. Monitoring: Are things drifting over time?
  7. Sunset: When should we retire this system?

Human-in-the-Loop

Not all decisions should be fully automated. Consider:

  • High stakes: Medical, legal, financial decisions
  • Low confidence: When the model is uncertain
  • Affected populations: Who cannot appeal?

Red-Teaming

Deliberately try to make your AI system behave badly:

  • Find failure modes before users do
  • Test for safety and bias vulnerabilities
  • Include diverse perspectives in red-team

Governance

  • Assign responsibility for AI systems
  • Create clear escalation paths
  • Document decisions and their rationale
  • Set up monitoring and alerting

Example

python
from anthropic import Anthropic
from dataclasses import dataclass, field
from datetime import datetime
from typing import Optional
import json

client = Anthropic()

@dataclass
class AIDecisionLog:
    """Audit log for AI decisions — critical for accountability"""
    decision_id: str
    timestamp: str = field(default_factory=lambda: datetime.now().isoformat())
    input_summary: str = ""
    model_used: str = ""
    output: str = ""
    confidence: float = 0.0
    human_review_required: bool = False
    human_reviewer: Optional[str] = None
    final_decision: Optional[str] = None
    flags: list = field(default_factory=list)

class ResponsibleAISystem:
    """AI system with built-in ethical safeguards"""

    HIGH_RISK_KEYWORDS = ["medical", "legal", "financial", "employment", "criminal"]
    CONFIDENCE_THRESHOLD = 0.85

    def __init__(self, system_name: str):
        self.system_name = system_name
        self.audit_log: list[AIDecisionLog] = []

    def assess_risk(self, query: str) -> tuple[str, list[str]]:
        """Determine risk level and required safeguards"""
        flags = []
        query_lower = query.lower()

        for keyword in self.HIGH_RISK_KEYWORDS:
            if keyword in query_lower:
                flags.append(f"high_risk_domain:{keyword}")

        risk_level = "high" if flags else "low"
        return risk_level, flags

    def make_decision(self, query: str, decision_id: str) -> AIDecisionLog:
        log = AIDecisionLog(
            decision_id=decision_id,
            input_summary=query[:200],
            model_used="claude-3-5-haiku-20241022"
        )

        risk_level, flags = self.assess_risk(query)
        log.flags = flags

        response = client.messages.create(
            model="claude-3-5-haiku-20241022",
            max_tokens=1024,
            system=f"""You are {self.system_name}. Make a decision and assess your confidence.
Respond in JSON: {{"decision": "...", "confidence": 0.0-1.0, "reasoning": "...", "caveats": []}}""",
            messages=[{"role": "user", "content": query}]
        )

        try:
            text = response.content[0].text
            start, end = text.find("{"), text.rfind("}") + 1
            result = json.loads(text[start:end])
            log.output = result.get("decision", "")
            log.confidence = result.get("confidence", 0)
        except Exception:
            log.output = response.content[0].text
            log.confidence = 0.5

        # Require human review for high-risk or low-confidence decisions
        if risk_level == "high" or log.confidence < self.CONFIDENCE_THRESHOLD:
            log.human_review_required = True
            log.flags.append("requires_human_review")

        self.audit_log.append(log)
        return log

    def print_audit_summary(self):
        print(f"
Audit Summary for {self.system_name}")
        print(f"Total decisions: {len(self.audit_log)}")
        flagged = [l for l in self.audit_log if l.human_review_required]
        print(f"Requiring human review: {len(flagged)} ({len(flagged)/len(self.audit_log):.0%})")

# Example usage
system = ResponsibleAISystem("Loan Decision Assistant")

queries = [
    "Should we approve a $50,000 home improvement loan for someone with a 720 credit score?",
    "What is the weather like today?",
    "Should this employee be promoted based on their performance review?",
]

for i, query in enumerate(queries):
    log = system.make_decision(query, f"DEC-{i+1:03d}")
    print(f"
[{log.decision_id}] Decision: {log.output[:100]}")
    print(f"  Confidence: {log.confidence:.0%} | Human review: {log.human_review_required}")
    if log.flags:
        print(f"  Flags: {', '.join(log.flags)}")

system.print_audit_summary()
Try it yourself — PYTHON