Skip to content

APIM AI Gateway: Add prompt/completion audit logging for government compliance #100

@mishraomp

Description

@mishraomp

Summary

Current OpenAI usage logging (openai-usage-logging fragment) captures token counts and metadata (model, tenant, subscription) but NOT the actual prompt text or completion text. There is no audit trail of what was asked and what was returned.

Gap

Government AI governance frameworks often require audit trails for model interactions - what prompts were sent, what responses returned, and whether any content safety issues were flagged. Without this, compliance audits have visibility into "how much" but not "what."

Proposed Implementation

  1. Create a new audit-logging policy fragment that captures:
    • context.Request.Body (post-PII-redaction, so anonymized)
    • context.Response.Body (completion text)
    • Content safety verdict (if llm-content-safety is implemented)
    • Tenant, subscription, model, and timestamp metadata
  2. Log to Application Insights custom events (or a dedicated Log Analytics workspace)
  3. Make it opt-in per tenant via an audit_logging_enabled flag in tenant tfvars
  4. Add the flag to templatefile() variables in stacks/apim/locals.tf

Considerations

  • Privacy: PII redaction runs before audit logging, so logged prompts would be anonymized for OpenAI requests
  • Storage costs: Full prompt logging significantly increases App Insights ingestion costs - consider sampling or a separate workspace
  • Retention: Define retention policies aligned with BC Gov records management
  • Data residency: Ensure logs stay in Canada East

Prerequisites

  • Confirm BC Gov audit requirements for AI model interactions
  • Assess App Insights cost impact with estimated request volume
  • Determine if a separate Log Analytics workspace is needed for audit data

Severity

MEDIUM - Depends on specific BC Gov audit requirements for AI services.

Context

Identified during APIM multi-tenancy and AI gateway policy gap analysis (Feb 2026).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions