Skip to content

feat(security): PII/PHI redaction for telemetry + EU AI Act Article 15 export (#398)#442

Open
Prateeks16 wants to merge 2 commits into
sreerevanth:mainfrom
Prateeks16:feat/pii-phi-redaction-398
Open

feat(security): PII/PHI redaction for telemetry + EU AI Act Article 15 export (#398)#442
Prateeks16 wants to merge 2 commits into
sreerevanth:mainfrom
Prateeks16:feat/pii-phi-redaction-398

Conversation

@Prateeks16

Copy link
Copy Markdown
Contributor

Closes #398

Summary

Implements the two CMP-003/CMP-004 deliverables from the issue: auto-redaction of PII/PHI in telemetry before it is persisted, and an EU AI Act Article 15 conformity export endpoint.

The compliance/governance layer already exists under agentwatch/governance/ (gdpr.py, hipaa.py, eu_ai_act.py, compliance_reporter.py + the /governance/compliance-report endpoint). The missing piece — and the focus of this PR — is the redaction layer and wiring it into the telemetry path.

What's added

  • agentwatch/security/redaction.py — a Redactor that masks PII and PHI as [REDACTED]:
    • Uses Microsoft Presidio (presidio-analyzer/presidio-anonymizer) for NER-based detection when installed (new optional redaction extra), and otherwise falls back to the regex detectors already maintained by the GDPR (CMP-001) and HIPAA (CMP-003) engines — so there's a single source of truth for the patterns and no hard dependency on the heavyweight Presidio stack.
    • Helpers: redact(), redact_payload() (recursive), redact_tool_call().
  • core/watcher.py — opt-in GenericAdapter(redact=True) scrubs each tool call's raw_command + arguments before the event is published and persisted.
  • api/server.pyGET /api/v1/governance/eu-ai-act-report returns the Article 15 technical documentation + conformity assessment as JSON, mapping AgentWatch's safety telemetry (risk scoring, red-team harness, blast-radius) to the Article 15 requirements.

Acceptance criteria

  • PII and PHI (SSNs, medical diagnoses, …) are masked as [REDACTED] before persistence — covered by redaction.py + the watcher opt-in.
  • Compliance report endpoint generates required evidence — the existing /governance/compliance-report plus the new /governance/eu-ai-act-report Article 15 export.

Design notes

  • Redaction is opt-in on the watcher to avoid imposing the cost (and Presidio model load) on every run; enable per-adapter with redact=True.
  • Reuses the governance regex patterns instead of duplicating them; Presidio is strictly optional (pip install agentwatch[redaction]).

Testing

tests/test_redaction.py: PII masking (SSN/email/phone), PHI masking (MRN/diagnosis/ICD), recursive payload redaction, redact_tool_call, the watcher opt-in (on/off), and the EU AI Act endpoint via TestClient.

pytest tests/test_redaction.py tests/test_watcher.py tests/test_compliance.py  -> all pass
ruff check / format (changed files)                                            -> clean

Note on scope / process

CONTRIBUTING flags security/compliance features for Discord discussion first — flagging here; happy to adjust. The issue's suggested paths (agentwatch/compliance/eu_ai_act.py) map to the existing agentwatch/governance/ module, which this PR builds on rather than duplicating.

The repo-wide ruff check . gate has pre-existing failures in unrelated test files on main; this PR's changed files are lint-clean.

…reerevanth#398)

CMP-003/004 — auto-redact PII/PHI before telemetry is persisted, and surface an
EU AI Act Article 15 conformity export.

- agentwatch/security/redaction.py: a Redactor that masks PII/PHI as [REDACTED].
  Uses Microsoft Presidio when installed (new optional `redaction` extra),
  otherwise falls back to the GDPR (CMP-001) and HIPAA (CMP-003) regex
  detectors — reusing their patterns, no hard dependency. Provides
  redact()/redact_payload()/redact_tool_call() helpers.
- core/watcher.py: opt-in `GenericAdapter(redact=True)` scrubs tool-call
  payloads (raw_command + arguments) before events are published/persisted.
- api/server.py: GET /api/v1/governance/eu-ai-act-report returns the Article 15
  technical documentation + conformity assessment as JSON.
- Tests: PII/PHI masking, payload recursion, tool-call redaction, the watcher
  opt-in, and the EU AI Act endpoint.
- Docs: CHANGELOG, MASTERLIST (CMP-003/004), and the `redaction` extra.
Copilot AI review requested due to automatic review settings June 19, 2026 08:47
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Prateeks16, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 11 minutes and 47 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 60238ae0-8bdb-433c-a943-928b33387590

📥 Commits

Reviewing files that changed from the base of the PR and between 3b1f4b5 and d2b2452.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • MASTERLIST_STATUS.md
  • agentwatch/api/server.py
  • agentwatch/core/watcher.py
  • agentwatch/governance/gdpr.py
  • agentwatch/governance/hipaa.py
  • agentwatch/security/redaction.py
  • pyproject.toml
  • tests/test_redaction.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

🧪 PR Test Results

Check Result
Tests (pytest tests/) ✅ success
Lint (ruff check .) ✅ success
Coverage (agentwatch) 73.39%

Python 3.12 · commit a6a2e30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in telemetry redaction layer to scrub PII/PHI before persistence and introduces an EU AI Act Article 15 JSON export endpoint under the existing governance module.

Changes:

  • Introduce agentwatch.security.redaction with Presidio (optional) + regex fallback redaction helpers for text, nested payloads, and tool calls.
  • Wire redaction into GenericAdapter via redact=True, and add GET /api/v1/governance/eu-ai-act-report.
  • Add a redaction optional dependency extra plus tests and status/changelog updates.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
agentwatch/security/redaction.py New redaction module implementing Presidio/regex PII/PHI masking utilities.
agentwatch/core/watcher.py Adds opt-in redaction hook for tool-call telemetry in the watcher adapter.
agentwatch/api/server.py Adds EU AI Act Article 15 report export endpoint.
pyproject.toml Adds optional redaction extra for Presidio dependencies.
tests/test_redaction.py Adds unit/integration tests for redaction behavior, watcher integration, and the new endpoint.
MASTERLIST_STATUS.md Updates compliance phase entries to reflect added deliverables/tests.
CHANGELOG.md Documents the new redaction feature and report endpoint under Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 309 to 312
# ── Safety gate (async path — full check_event with approval) ──
if is_tool_like:
tool_call = _build_tool_call_data(method_name, args, kwargs)
tool_call = self._maybe_redact(_build_tool_call_data(method_name, args, kwargs))
safety_event = AgentEvent(
Comment on lines 373 to 377
# ── Safety gate (sync path — pattern match only, no approval) ──
if is_tool_like:
tool_call = _build_tool_call_data(method_name, args, kwargs)
tool_call = self._maybe_redact(_build_tool_call_data(method_name, args, kwargs))
try:
blocked, reasons = self._safety_engine.check_tool_call_sync(tool_call)
Comment thread agentwatch/api/server.py Outdated
Comment on lines +1080 to +1092
"""EU AI Act Article 15 conformity export (CMP-004).

Maps AgentWatch's safety telemetry to the Article 15 requirements and
returns the technical documentation plus a conformity assessment as JSON.
"""
from agentwatch.governance.eu_ai_act import EUAIActPackage, TechnicalDocumentation

doc = TechnicalDocumentation(
system_name="AgentWatch-monitored AI system",
intended_purpose="Observability, safety, and reliability layer for AI agents",
risk_category="high",
data_governance={"pii_phi_redaction": "enabled", "retention": "policy-driven"},
robustness_evidence=[
Comment thread agentwatch/security/redaction.py Outdated
Comment on lines +19 to +21
from agentwatch.governance.gdpr import _PII_PATTERNS
from agentwatch.governance.hipaa import _PHI_PATTERNS

@sreerevanth

Copy link
Copy Markdown
Owner

@Prateeks16
Thanks for the contribution.

The redaction functionality is useful and the overall direction makes sense. However, there are a few issues that need to be addressed before merge:

  • Safety checks should run against the raw tool call data. Redaction currently occurs before safety evaluation, which may hide signals needed by the SafetyEngine and alter block/allow decisions.
  • The EU AI Act export currently reports compliance-related fields that appear to be static rather than derived from runtime configuration or telemetry.
  • Please avoid relying on private governance module internals where possible and expose public accessors/constants instead.

Once these items are addressed, I'll take another look.

…export, public patterns

Maintainer feedback on sreerevanth#398:

1. Safety must evaluate the raw tool call, not a redacted copy. Redaction ran
   before the safety check, masking signals (paths/secrets/identifiers) the
   SafetyEngine relies on and potentially altering block/allow decisions. The
   watcher now checks the raw payload and scrubs PII/PHI only when building the
   event that is published/persisted (new _redact_event helper). Added a
   regression test asserting safety sees the raw command while the published
   event is redacted.

2. The EU AI Act Article 15 export reported static literals. It now derives
   data governance, accuracy metrics, robustness evidence, human-oversight
   description, and record-keeping (decision log) from live safety telemetry
   and the active policy.

3. Stop importing private governance internals. gdpr/hipaa now expose public
   pii_patterns() / phi_patterns() accessors; the redactor uses those.
@Prateeks16

Copy link
Copy Markdown
Contributor Author

Thanks for the review — all three addressed in the latest push:

  1. Safety now runs on raw data. Redaction no longer happens before the safety check. The watcher evaluates the raw tool call, then scrubs PII/PHI only when building the event that's published/persisted (new _redact_event helper, both sync and async paths). Added a regression test asserting the SafetyEngine sees the unredacted command while the published TOOL_CALL event is redacted.

  2. EU AI Act export is now runtime-derived. The Article 15 endpoint pulls data governance, accuracy metrics, robustness evidence, human-oversight description, and the decision log (record-keeping) from live safety telemetry (safety_engine.stats()), the active policy, and recent sessions — no more static literals. Response now includes a telemetry block.

  3. No more private internals. gdpr and hipaa expose public pii_patterns() / phi_patterns() accessors; the redactor consumes those instead of _PII_PATTERNS / _PHI_PATTERNS.

Full suite green except one pre-existing CLI test (test_export_invalid_format) unrelated to this PR — it reads result.stderr, fixed separately in #449.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Premium] CMP-003 & CMP-004: HIPAA Compliance & EU AI Act Package

3 participants