feat(mcp): redact structured PII from $mcp_intent + stronger prompt - #923
Conversation
$mcp_intent is agent-narrated free text written into the injected `context` argument, so a model can narrate personal data it read aloud. Add always-on redaction of structured identifiers — emails, IPv4/IPv6, US SSNs, Luhn-valid card numbers, and phone numbers — scoped to the intent only (structured tool arguments and responses are untouched, since the same shapes are often legitimate there). Also strengthen the default `context` prompt so agents are less likely to write personal data and refer to people by role. Ports PostHog/posthog-js#4783 to the Python SDK. Generated-By: PostHog Desktop Task-Id: d2dffe4e-4642-457d-b371-89333d0388af
posthog-python Compliance ReportDate: 2026-09-07 10:36:13 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Prompt To Fix All With AI### Issue 1
posthog/test/mcp/test_pipeline.py:324-331
**Unreliable performance measurement**
This test checks one execution against a one-second wall-clock limit. The repository requires performance tests to use clear thresholds such as average duration and standard deviation. A single measurement is vulnerable to scheduler noise and provides weak evidence about regressions, so this requirement must be satisfied before merging.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "feat(mcp): redact structured PII from $m..." | Re-trigger Greptile |
gesh
left a comment
There was a problem hiding this comment.
QA Swarm review complete. See inline comments.
|
Note 🤖 Automated comment by QA Swarm — not written by a human Multi-perspective review: router (cheap-first pass) + delegated reviewers as warranted Verdict: 💬 APPROVE WITH NITS (round 1 @ 9c4ec97)A well-scoped, well-tested port of posthog-js#4783. The router independently fuzzed every redaction pattern for ReDoS (linear up to ~250k chars), confirmed the Luhn card scan / IPv6 / phone boundary logic, and verified redaction is wired only onto Key findings
ConvergenceNone (single router pass; no delegation warranted for a LOW-danger, well-tested diff). Reviewer summaries
Automated by QA Swarm — not a human review |
Generated-By: PostHog Desktop Task-Id: d2dffe4e-4642-457d-b371-89333d0388af
sanitize_captured_value can hand redact_pii a non-str value at runtime (it returns Any), but the str-typed parameter made mypy treat the non-str guard as statically unreachable. Widening to Any matches the function's actual runtime contract and keeps the guard live. Generated-By: PostHog Desktop Task-Id: d2dffe4e-4642-457d-b371-89333d0388af
Ports PostHog/posthog-js#4783 to the Python SDK.
$mcp_intentis agent-narrated free text written into the injectedcontextargument, so a model can narrate personal data it read aloud. Two defensive layers:arguments/responses are left untouched, since the same shapes are often legitimate there. Best-effort for well-defined shapes, not free-form names/addresses. Email quantifiers are bounded to avoid quadratic backtracking; every card in a multi-card span is redacted.contextprompt telling the agent not to repeat/paraphrase/infer personal data and to refer to people by role.redact_piilives in_sanitization.pyand runs onuser_intentafter the existing token/secret scrub — a single choke point covering every adapter and the manualPostHogMCPpath.Tests
New parametrized redaction + intent-scoping tests in
posthog/test/mcp/test_pipeline.py, mirroring the JS suite (per-identifier cases, multi-identifier, multi-card span, anti-quadratic timing guard, andsanitize_eventscoping). Full MCP suite passes on both SDK v1 and v2 (Python 3.10 and 3.14).Created with PostHog Desktop