DEV Community

Heath
Heath

Posted on • Originally published at tracecontinuity.com

PII Redaction for AI Agents: Why It Can't Be an Afterthought

Originally published at tracecontinuity.com

The PII problem in AI memory is not what you think it is

Most engineering teams building AI agents understand that they shouldn't store raw PII. Ask any developer and they'll say: of course we're not storing social security numbers in the vector store.

But PII leaks through AI memory systems in ways that are less obvious — and the developer's mental model of "just don't store the sensitive parts" is not sufficient.

This post explains how PII actually leaks, why afterthought redaction approaches fail, and what architectural PII redaction for AI agents looks like.


How PII enters AI memory without anyone intending it to

Implicit extraction

AI agents don't just store what you explicitly tell them to store. They extract facts. When a language model processes a conversation and derives memories from it, the extracted facts often contain PII the agent never explicitly received.

Example: a user says "my appointment is next Tuesday at the clinic on Maple Street." The agent may extract and store: user_name: Sarah Chen, medical_appointment: 2026-04-29, location: Maple Street Clinic. The user never stated their name — the model inferred it from earlier context.

Contextual embedding

Vector embeddings encode semantic meaning. A memory stored as "the patient prefers morning appointments" embeds differently when it was derived from a conversation that included the patient's name, diagnosis, and insurance information.

Summarization artifacts

Long-context summarization is a common memory strategy: compress a long conversation into a summary, store the summary. LLM summarization is nondeterministic and can preserve PII that was incidental rather than salient.

Third-party data passthrough

When agents access external tools — CRMs, EMRs, financial databases — the data they retrieve gets incorporated into context. A healthcare agent that queries a patient record may inadvertently store memory containing PHI.


Why afterthought PII redaction fails

The intuitive solution is to add a redaction layer: before writing to the memory store, scan for PII and remove it. This is better than nothing. It is not sufficient.

The scanning problem: Named entity recognition (NER) and regex-based PII detection have false negative rates. They miss non-standard formats, contextual PII, and domain-specific identifiers.

The granularity problem: Redaction that removes identifiers but preserves context can still be identifying. "The patient with the rare genetic condition who lives in the small town near the manufacturing plant" is not anonymized just because the name was stripped.

The timing problem: If redaction happens after the AI model has already processed the data, the window for a leak is open. An agent that crashes between inference and redaction may write unredacted data.

The HIPAA AI agents problem: HIPAA requires that PHI protections apply to all forms of PHI — not just the formats you anticipated.


What architectural PII redaction looks like

The right approach moves PII protection from an application-layer concern to an infrastructure-layer invariant.

Scan before storage, not after

In Trace Continuity's architecture, every memory write is intercepted at the API layer before it reaches storage. The redaction pipeline runs synchronously on the memory content:

// Developer writes a memory
await traceContinuity.remember({
  agent: "intake-bot",
  fact: "Patient prefers morning appointments. DOB: 1978-04-15.",
  retention: "365d",
  access: ["clinical-ops"]
});
// Before any storage occurs:
// 1. PII scanner runs (DOB detected)
// 2. DOB is redacted: "Patient prefers morning appointments. DOB: [REDACTED]."
// 3. Redaction event is logged with: field type, redaction timestamp, agent ID
// 4. Redacted version is stored
// 5. Original is never written to persistent storage
Enter fullscreen mode Exit fullscreen mode

The developer doesn't manage the redaction pipeline. It runs for every write, on every memory, with no opt-out path.

Typed PII detection, not just regex

Trace Continuity's redaction engine detects PII by type: names, emails, phone numbers, SSNs, dates of birth, account numbers, addresses, medical record numbers, and custom patterns configurable per tenant.

Redaction events are first-class audit objects

Every redaction creates an immutable audit record: what type of PII was detected, in which memory, from which agent, at what time, and what action was taken. This audit trail is separate from the memory store itself.


The AI data protection architecture that works

Wrong approach: Build AI agent → add memory → add redaction as a cleanup step → discover gaps in production.

Right approach: Use a memory infrastructure layer where redaction is the pipeline, not a plugin. Governance is not something you add to AI memory. It is the condition under which AI memory operates.

This is especially true for:

  • HIPAA AI agents — PHI protection must be demonstrable, not asserted
  • GDPR-compliant AI — Data minimization is a GDPR principle
  • SOC 2 Type II — Auditors want to see that data protections are enforced systematically

Trace Continuity provides pre-storage redaction, typed detection across 15+ PII categories, tenant-configurable rules, and an immutable redaction audit log. Start for free →

Top comments (0)