Azure-AI_Foundry

Lesson 3: Governance and Compliance

Introduction

Building AI responsibly goes beyond content filtering β€” it requires organizational governance, regulatory compliance, and systematic processes for reviewing, deploying, and monitoring AI systems. This lesson covers the frameworks, tools, and best practices for governing AI at enterprise scale.

πŸ“– Reference: Microsoft Responsible AI


AI Governance Framework for Enterprises

A robust AI governance framework includes five pillars:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  AI GOVERNANCE FRAMEWORK                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Policy &   β”‚  Risk       β”‚  Technical  β”‚  People &    β”‚
β”‚  Standards  β”‚  Assessment β”‚  Controls   β”‚  Process     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ AI use      β”‚ Impact      β”‚ Content     β”‚ Review       β”‚
β”‚ policies    β”‚ assessments β”‚ filters     β”‚ boards       β”‚
β”‚ Data        β”‚ Risk        β”‚ Logging &   β”‚ Training &   β”‚
β”‚ governance  β”‚ registers   β”‚ auditing    β”‚ awareness    β”‚
β”‚ Model       β”‚ Bias        β”‚ Access      β”‚ Incident     β”‚
β”‚ standards   β”‚ testing     β”‚ controls    β”‚ response     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Establishing an AI Review Board

# Example: AI deployment request tracking
ai_deployment_request = {
    "application_name": "Customer Service Bot",
    "model": "gpt-4o",
    "use_case": "Automated customer support responses",
    "data_classification": "Confidential",
    "risk_level": "Medium",
    "content_filters": "Default Microsoft filters + custom blocklist",
    "data_residency": "EU (West Europe)",
    "review_status": "Pending",
    "reviewer": "AI Ethics Board",
    "requested_by": "Product Team Alpha",
    "date_submitted": "2024-11-15",
    "impact_assessment_url": "https://internal.company.com/ai-reviews/cs-bot-001"
}

Data Privacy and Data Residency

Key Principles

  1. Data minimization β€” Only collect and process data necessary for the AI task
  2. Purpose limitation β€” Use data only for the stated purpose
  3. Data residency β€” Ensure data is processed in compliant geographic regions
  4. Retention policies β€” Define how long AI interaction data is stored

Azure Data Residency Controls

# When creating Azure OpenAI resources, choose regions that match
# your data residency requirements

# Example: Ensure EU data stays in EU
resource_config = {
    "resource_group": "rg-ai-eu",
    "location": "westeurope",           # Data processed in EU
    "kind": "OpenAI",
    "sku": "S0",
    "properties": {
        "networkAcls": {
            "defaultAction": "Deny"     # Restrict network access
        }
    }
}

# Azure AI Foundry project configuration
project_config = {
    "hub_name": "ai-hub-eu",
    "location": "westeurope",
    "storage_account": "staiprojecteu",  # EU storage
    "key_vault": "kv-ai-project-eu",     # EU key vault
    "description": "EU-compliant AI project for GDPR-regulated workloads"
}

πŸ“– Reference: Azure data residency


Transparency Notes and Model Cards

Transparency Notes

Microsoft publishes Transparency Notes for each AI service, documenting:

Creating Your Own Model Cards

For fine-tuned or custom models, document:

model_card = {
    "model_name": "customer-intent-classifier-v2",
    "base_model": "gpt-4o-mini",
    "fine_tuning_date": "2024-10-01",
    "training_data": {
        "source": "Internal customer support tickets (anonymized)",
        "size": "50,000 labeled examples",
        "date_range": "2023-01 to 2024-09",
        "demographics": "Global customer base, English-only",
        "known_gaps": "Limited representation of APAC region queries"
    },
    "evaluation_results": {
        "accuracy": 0.94,
        "f1_score": 0.92,
        "bias_assessment": "Tested across 8 demographic groups, max variance 3%",
        "failure_modes": [
            "Struggles with multi-intent queries",
            "Lower accuracy on technical jargon"
        ]
    },
    "intended_use": "Routing customer support tickets to appropriate teams",
    "out_of_scope": "Not for making financial decisions or medical advice",
    "risk_level": "Low β€” assists human agents, does not auto-respond",
    "review_frequency": "Quarterly performance review, annual bias audit"
}

πŸ“– Reference: Transparency Notes for Azure AI


Logging and Auditing AI Interactions

Comprehensive Audit Logging

import logging
import json
from datetime import datetime, timezone

class AIAuditLogger:
    """Structured audit logging for AI interactions."""

    def __init__(self):
        self.logger = logging.getLogger("ai_audit")
        handler = logging.FileHandler("ai_audit.log")
        handler.setFormatter(logging.Formatter('%(message)s'))
        self.logger.addHandler(handler)
        self.logger.setLevel(logging.INFO)

    def log_interaction(self, request_id: str, user_id: str,
                        model: str, prompt: str, response: str,
                        content_filter_results: dict,
                        tokens_used: dict, latency_ms: float):
        """Log a complete AI interaction for auditing."""
        audit_record = {
            "timestamp": datetime.now(timezone.utc).isoformat(),
            "request_id": request_id,
            "user_id": user_id,
            "model": model,
            "prompt_length": len(prompt),
            "response_length": len(response),
            "content_filter": content_filter_results,
            "tokens": tokens_used,
            "latency_ms": latency_ms,
            "prompt_hash": hash(prompt),  # For deduplication, not the actual prompt
            "safety_flags": self._check_safety_flags(content_filter_results)
        }
        self.logger.info(json.dumps(audit_record))

    def _check_safety_flags(self, filter_results: dict) -> list:
        flags = []
        for category, result in filter_results.items():
            if result.get("severity", 0) >= 2:
                flags.append(f"{category}:severity-{result['severity']}")
        return flags

    def log_safety_event(self, request_id: str, event_type: str,
                         details: str):
        """Log safety-related events (blocks, jailbreak attempts, etc.)."""
        event = {
            "timestamp": datetime.now(timezone.utc).isoformat(),
            "request_id": request_id,
            "event_type": event_type,
            "details": details,
            "severity": "HIGH" if "jailbreak" in event_type else "MEDIUM"
        }
        self.logger.info(json.dumps(event))

What to Log (and What NOT to Log)

βœ… Log ❌ Do NOT Log
Request/response metadata Full user prompts (PII risk)
Content filter results Personal identifiable information
Token usage and costs Authentication credentials
Safety events and blocks System prompt contents
Model version and deployment Internal API keys
Latency and performance data Raw user data without consent

Building a Responsible AI Review Process

Pre-Deployment Checklist

## Responsible AI Pre-Deployment Review

### 1. Use Case Assessment
- [ ] Use case clearly defined and documented
- [ ] Impact assessment completed
- [ ] Risk level classified (Low / Medium / High / Critical)
- [ ] Stakeholders identified and consulted

### 2. Technical Controls
- [ ] Content filters configured and tested
- [ ] Prompt shields enabled
- [ ] Custom blocklists for domain-specific terms
- [ ] Rate limiting configured
- [ ] Input/output logging enabled

### 3. Data Governance
- [ ] Data residency requirements met
- [ ] PII handling documented
- [ ] Data retention policy defined
- [ ] User consent mechanisms in place

### 4. Testing & Evaluation
- [ ] Red-team testing completed
- [ ] Bias evaluation across demographic groups
- [ ] Groundedness evaluation (for RAG applications)
- [ ] Performance benchmarks documented

### 5. Operational Readiness
- [ ] Monitoring dashboards configured
- [ ] Alert thresholds set for safety events
- [ ] Incident response plan documented
- [ ] Human escalation path defined
- [ ] Rollback procedure tested

EU AI Act and Industry-Specific Compliance

EU AI Act Risk Classification

Risk Level Requirements AI Foundry Examples
Unacceptable Banned (social scoring, manipulation) N/A β€” do not build these
High Risk Conformity assessment, registration HR screening, credit scoring
Limited Risk Transparency obligations Chatbots, content generation
Minimal Risk No specific requirements Spam filters, recommendations

Industry-Specific Considerations

πŸ“– Reference: Azure compliance offerings


πŸ’‘ Best Practices

  1. Maintain a Responsible AI log of all deployed models and their risk assessments
  2. Review quarterly β€” schedule regular reviews of AI system performance and safety metrics
  3. Document everything β€” treat AI governance like financial auditing: if it isn’t documented, it didn’t happen
  4. Start with high-risk use cases β€” prioritize governance for customer-facing and decision-making AI
  5. Train your team β€” ensure all developers understand Responsible AI principles before building
  6. Plan for incidents β€” have a playbook for when AI produces harmful content in production

Hands-On Exercise

  1. Create a model card for a hypothetical fine-tuned model in your domain
  2. Implement the AIAuditLogger and generate sample audit records
  3. Complete the Responsible AI pre-deployment checklist for a sample application
  4. Classify three AI use cases under the EU AI Act risk framework
  5. Design a monitoring dashboard for AI safety metrics

Key Takeaways


Additional Resources


Next: Knowledge Check