← Field Notes
·12 min read·Heath Parish

Tokenization vs Encryption for AI Memory: Why Encryption Alone Will Not Protect PHI, PII, or CUI

Encryption protects data from outsiders. Tokenization protects data from the system itself. For AI memory that stores PHI, PII, or CUI, the difference decides whether a breach becomes a notification event or a nonissue.

When a security team hears that an AI memory system stores sensitive data, the first question is almost always the same. Is it encrypted? The vendor answers yes. Encryption at rest with AES-256, encryption in transit with TLS 1.3, keys managed in a hardware security module. The security team checks the box and moves on.

That check is necessary. It is not sufficient. Encryption protects data from a specific class of attacker, mainly the one who steals a disk or intercepts a network packet. It does very little against the class of attacker that matters most for AI memory: the authorized user, the compromised session, the misbehaving agent, or the developer who writes a query that reads more than they should.

Tokenization protects against that second class. This post explains the difference, why it matters specifically for AI memory, and why regulated organizations should treat tokenization of sensitive fields as a baseline requirement, not an optional enhancement.

What Encryption Actually Does

Encryption transforms data into ciphertext that can only be read with the correct key. Encryption at rest keeps data unreadable on disk. Encryption in transit keeps data unreadable on the wire. Both are essential and both are well understood.

The critical property of encryption is that it is reversible by anyone with the key. That property is a feature when the legitimate user needs to read the data. It is a weakness when the attacker becomes a legitimate user, either by compromising a session, stealing a token, or exploiting an application that has legitimate access.

In an AI memory system, the application always has the key. It has to. The application reads the data to serve retrieval requests, run queries, and produce responses. Encryption at the storage layer is transparent to the application. That means it is transparent to any attacker who reaches the application layer. A SQL injection, a compromised service account, a prompt injection that tricks an agent into retrieving records it should not, all of these bypass encryption entirely because they operate at the layer where the key is already in use.

What Tokenization Does Differently

Tokenization replaces sensitive values with non-sensitive substitutes, called tokens, that have no exploitable mathematical relationship to the original value. The mapping from token to original value lives in a separate, tightly controlled store. Only code paths with explicit authority to detokenize can recover the original value.

The practical effect is that the memory system stores tokens, not sensitive data. A query that returns a memory record returns tokens. A vector search that surfaces a matching document surfaces tokens. A backup that gets exfiltrated contains tokens. An overly permissive query written by a developer returns tokens. In every case, the sensitive value never left the token vault, and no key was ever exposed to the memory layer.

This is the difference that matters. Encryption protects data from the outside. Tokenization protects data from the inside.

Why AI Memory Needs Both

AI memory has three properties that make it particularly hostile to encryption-only protection.

  • It is designed to be retrieved. The whole point of the system is that it returns stored context on demand. Every retrieval is, by definition, a decryption event. The blast radius of any authority mistake is the full sensitivity of the retrieved data.
  • It is queried by AI, not by humans. An agent may retrieve dozens or hundreds of records to answer a single question. Human review of each retrieval is not feasible. The system has to protect the data itself, not rely on the retriever to be careful.
  • It persists across sessions. Data written under one authority context may be retrieved under a completely different one months later. Encryption does not distinguish between the two. Tokenization, paired with an authority check on detokenization, does.

For regulated data, this changes the calculus. HIPAA's Safe Harbor provisions treat tokenized identifiers differently from encrypted identifiers because tokenization removes the identifier from the record entirely. Under NIST SP 800-171, tokenized CUI can materially reduce the scope of controls that apply to the memory system. Under GDPR, tokenization is one of the explicitly named techniques for pseudonymization, which reduces obligations under several articles.

None of that is available if the only protection is encryption at rest.

The Detection Problem

Tokenization only works if the system knows which fields are sensitive. In a traditional application with a fixed schema, that is straightforward. Social Security number goes in the SSN column, and the SSN column is tokenized. AI memory does not have a fixed schema. It stores free-form text, structured documents, nested objects, arrays, and content generated by the model itself. Sensitive data can appear anywhere.

This is why detection has to happen at the execution path, before storage, and it has to be recursive. A well-designed tokenization layer walks the entire payload, including nested objects and array elements, applies pattern detection and classification to every string it encounters, and tokenizes anything that matches a sensitive pattern. Detection has to cover:

  • Structured identifiers such as Social Security numbers, credit card numbers, medical record numbers, and account numbers.
  • Semi-structured identifiers such as email addresses, phone numbers, and IP addresses.
  • Unstructured identifiers such as names, addresses, and dates in narrative text.
  • Domain-specific identifiers such as ICD codes paired with personal identifiers, matter numbers paired with client names, or program identifiers paired with technical data.

Trace Continuity's tokenization layer runs recursively over every write to governed memory, walks nested structures, and tokenizes matches before the payload is stored. Automated tests verify that recursive detection continues to work as the codebase evolves. A failure of the detection layer is caught in the build, not in production.

Authority on Detokenization

Tokenization without an authority model on detokenization is a locked box with the key taped to the outside. The tokens have to be exchanged for original values at some point, and the exchange is where the sensitive data becomes visible. If any code path can detokenize, tokenization has bought nothing.

The correct pattern binds detokenization to execution-time authority verification. When a retrieval returns tokens, the request to detokenize each token is evaluated against the current authority of the actor, the classification of the field, the applicable policy, and the reason for the request. Detokenization proceeds only for fields the actor is currently authorized to see. The rest are returned as tokens, redacted, or replaced with a policy-defined placeholder.

This is what allows a retrieval to succeed for a limited audience without exposing the full record. A clinical AI can retrieve a patient summary and see the clinically relevant fields while insurance identifiers remain tokenized. A legal AI can retrieve a matter memo and see the analysis while the client name remains tokenized until a conflict check passes. A defense AI can retrieve a technical document and see the general description while the controlled parameters remain tokenized for anyone without the necessary program access.

What a Breach Looks Like With and Without Tokenization

The clearest way to see the value of tokenization is to walk through what happens when something goes wrong.

Scenario one, encryption only. An attacker compromises the AI memory application through a prompt injection that convinces an agent to run a broad retrieval. The application has the encryption key. The retrieval returns the underlying records in the clear. The attacker exfiltrates a large volume of PHI, PII, or CUI. The organization has a reportable breach, notification obligations, regulatory scrutiny, and potential liability.

Scenario two, tokenization with authority-bound detokenization. The same attack succeeds in triggering a broad retrieval. The retrieval returns tokens. The detokenization step evaluates the actor's authority for each field and finds no legitimate basis for detokenizing sensitive identifiers at this scale. The tokens are returned as tokens. The attacker exfiltrates a large volume of non-sensitive substitutes. The sensitive values never left the vault. The organization has an incident to investigate but no reportable breach of sensitive data.

The difference between these two scenarios is not the sophistication of the attack. It is the architectural decision to protect data from the inside, not just the outside.

Where Tokenization Is Not a Substitute

Tokenization is not a general-purpose replacement for encryption. Encryption is still required for data in transit, for backups of the token vault itself, for storage of the tokens where operational security is expected, and for a long list of other purposes that have nothing to do with AI memory. The point is not to choose one over the other. The point is to recognize that encryption protects a specific threat model and tokenization protects a different one, and that AI memory has to defend against both.

Tokenization is also not a substitute for authority verification. If any authenticated user can detokenize any token, tokenization has been reduced to obfuscation. The value comes from binding detokenization to execution-time authority checks, so the authority to see the sensitive value has to exist at the moment of retrieval, not at the moment of storage.

The Practical Requirement

For any AI memory system that will store data governed by HIPAA, HIPAA-adjacent state laws, GDPR, CCPA, CMMC, ITAR, or attorney-client privilege, the practical requirement is now a stack, not a single control.

  • Encryption at rest and in transit, with keys in a hardware security module.
  • Recursive detection of sensitive fields on every write, covering nested objects, arrays, and free-form text.
  • Tokenization of detected sensitive fields before anything is written to governed memory.
  • A token vault isolated from the memory store, with its own access controls and audit trail.
  • Execution-time authority verification on every detokenization request, evaluated against the current authority of the actor and the classification of the field.
  • Audit evidence that records what was tokenized, what was detokenized, for whom, under what authority, and under what policy.

An AI memory system that offers only the first item on this list is a system that has confused the outside threat model with the inside one. In regulated sectors, that confusion has become expensive.

For a broader discussion of why governance belongs in the execution path and not in an after-the-fact review, see "AI Governance Cannot Stop at Authorization." For the technical primer on execution-time authority verification that underlies the detokenization pattern described here, see "Execution-Time Authority Verification: What It Is, Why It Matters, and How It Works." For the sector-specific view, see "Why Hospitals, Law Firms, and Defense Contractors Cannot Deploy AI Without Governed Memory."

Encryption protects the disk. Tokenization protects the data. AI memory needs both, and the second one is the one most teams have not built yet.

Trace Continuity Labs — Governed memory infrastructure with recursive sensitive-data detection, tokenization, and authority-bound detokenization.

TokenizationEncryptionPIIPHICUIAI MemoryData ProtectionCompliance