How to Prevent PHI Persistence in n8n Chat Memory
Stop PHI before the memory write, not after. Map every point where PHI can enter an n8n agent flow, then combine pre-memory redaction, short-lived session keys, scheduled purge of Postgres memory tables, and memory-free paths for PHI-bearing workflows. Retain evidence that each control ran before persistence.
Map where PHI enters and persists
- 1
1. User input
Patients, clinicians or staff may type names, dates of birth, record numbers or clinical details into the chat.
- 2
2. Tool output
Database lookups, EHR queries and API responses can return PHI the user never typed, and the agent may carry it into memory.
- 3
3. Model response
The model can repeat or combine PHI from earlier turns, so its replies need the same treatment as inputs.
- 4
4. Memory write
This is the last point of control. Anything that reaches the node is persisted under its session ID.
- 5
5. Downstream copies
Backups, replicas, exports and admin access paths extend wherever the table goes.
Implementation checklist and evidence to retain
- Inventory workflows using Simple Memory or Postgres Chat Memory and classify PHI exposure.
- Test memory node behavior and settings in a non-production instance and record the n8n version.
- Remove memory from PHI-bearing workflows where continuity is not essential.
- Redact or block PHI before every memory write, and test against realistic samples.
- Set session-key rules, a purge schedule, and explicit backup and replica expiry.
- Retain, per event, the policy decision, action taken, timestamp, workflow and session identifier.
How n8n memory nodes turn conversations into stored PHI
The Simple (Window Buffer) Chat Memory node keeps conversational context in n8n process memory. The Postgres Chat Memory node writes it to a Postgres table. In both cases the stored content is the full message text, so any PHI in a user message or a tool response is stored with it. The nodes offer little built-in control over what is written.
Three settings shape persistence: the session ID that keys each conversation, the context window length that governs how much history returns to the model, and, for Postgres, the table name. Treat the context window as a prompt-size control, not a storage control, and confirm in a non-production instance what your n8n version actually retains. Record the version you tested.
The compliance consequence is scope. The HIPAA Security Rule sets national standards for electronic PHI that a covered entity or business associate creates, receives, uses or maintains. If a memory table holds PHI, the database plausibly brings its backups, replicas and access paths into that scope. Compliance counsel should confirm that reading for your environment.
Compare the four mitigation patterns
No single pattern is sufficient for PHI-bearing workflows. The tradeoffs below reflect engineering judgment, and most production designs combine at least two.
- Pre-memory redaction: Remove or mask identifiers before the memory write, for example in a Code node. Preserves conversational context but depends on detection quality, so false negatives still persist. Test against realistic PHI samples and document misses.
- Session-key and TTL design: Use short-lived, non-identifying session IDs and expire sessions quickly. Limits exposure and simplifies deletion, but does not remove PHI already written and does not by itself expire backups.
- Scheduled purge of Postgres memory tables: A scheduled SQL deletion enforces a retention window. It is simple and auditable, but PHI exists until the next run, and backups and replicas need their own expiry.
- No memory for PHI-bearing workflows: Route PHI flows through a path with no memory node and pass only the context each call needs. Strongest on minimizing storage, but it costs conversational continuity and needs routing that reliably identifies PHI flows.
Limits of regex-only redaction, backups and retention
Pattern matching catches structured identifiers such as phone numbers or record numbers in predictable formats. It is weaker on free text: names, addresses, and clinical details described in ordinary sentences are harder to match. Treat any pattern-based redaction as risk reduction, not de-identification, and measure its false negative rate on your own data.
Purge and TTL controls also have a boundary. Deleting rows from a live table does not delete copies in backups or replicas. Decide how long backups are kept, whether restored data is re-purged, and who can query the table in the meantime.
On retention, HHS guidance states that the HIPAA Rules generally do not require a business associate to maintain ePHI beyond the time it provides services to a covered entity or business associate. That supports setting explicit deletion timelines for memory stores rather than keeping history by default. Do not carry other retention periods in the regulation, such as the six-year documentation requirement for designations, over to chat logs. A proposed amendment to the Security Rule was published in January 2025; as of November 2026, design to the existing rule and watch its status.
Enforcing policy at runtime in the execution path
The patterns above are built by hand, per workflow, and each one needs its own evidence. A runtime approach moves the decision into the execution path. Trussed enforces policy on individual interactions and tool calls, with allow, redact and block outcomes, so PHI can be redacted or blocked before it reaches a model call, a tool call or a memory write. Enforcement happens at runtime, not through review after the fact.
The same enforcement generates audit-ready evidence mapped to HIPAA, which supports the audit controls expectation in 164.312(b). Each decision produces a record of what was allowed, redacted or blocked. Trussed can be self-managed in the customer cloud, with configurable retention and data residency, so the evidence store does not become a new uncontrolled copy of PHI. It runs in production with healthcare and pharma organizations.
Runtime enforcement does not remove the need for memory design. Session keys, purge schedules and memory-free paths still limit what exists to be protected, and redaction quality still needs testing.
Where PHI can persist in an n8n memory flow
Entry
User input and tool output carry PHI into the agent.
Intercept
Redact or block content before the memory write.
Persist
Process memory or Postgres tables, then backups and replicas.
Expire
Session-key design and scheduled purge limit retention.
Evidence
Record the decision, action, timestamp and session.
Show that PHI was stopped before it was stored
Talk to an expert about enforcing allow, redact and block policy in the execution path and producing audit-ready evidence for your AI agent workflows.
Talk to an ExpertHow does your AI governance program compare?
See where your program has gaps in less than 2 minutes.