I Built an Open-Source Governance Layer for the Claude API — Here's Why and How
Описание и применение
Создана открытая библиотека для управления использованием Claude API, обеспечивающая проверку PII, блокировку ключевых слов, контроль длины запросов, бюджетирование токенов и неизменяемые журналы аудита.
Задача
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.
Результат
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.
Рабочий процесс
- 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
Доказательства
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.
- Дата записи: 2026-09-18T19:30:29.434Z