I Built an Open-Source Governance Layer for the Claude API — Here's Why and How
Description and use
An open‑source layer for the Claude API adds PII filtering, keyword blocking, prompt length limits, token budgeting, alerts, and tamper‑evident audit logs with minimal overhead.
Problem
Enterprise teams need to enforce PII protection, audit logging, cost control, and access governance when using the Claude API, but the SDK provides no built‑in compliance features.
Outcome
The kit adds a single‑line install, zero‑infra, and <10 ms overhead while providing PII detection, keyword blocking, prompt length enforcement, cost budgeting, alerts, and tamper‑evident audit logs.
Workflow
- Install the package via pip
- Instantiate GovernanceLayer with PII filter, blocked keywords, and prompt length limits
- Instantiate TokenMonitor with daily budget and alert threshold
- Create an AgentOrchestrator passing governance and monitor
- Create an agent with system prompt and persona
- Run the agent with a user ID
- Handle GovernanceViolation exceptions
- Inspect result content, cost, and governance status
Evidence
Every call goes through five stages: GovernanceLayer (pre‑flight) – PII scan, blocked keywords, length guard → Claude API call → GovernanceLayer (post‑response) – PII in output, GxP citation check → TokenMonitor – cost calculation, budget enforcement, alerts → AuditLogger – append‑only SHA‑256 tamper‑evident record → RunResult
I made a deliberate choice: governance decisions use compiled regex patterns, not another model call.
- Record date: 2026-09-18T19:30:29.434Z