An implementation pattern for context-preserving masking

The pattern has four parts, each described in the table below and expanded in the sections that follow.

Redaction pattern that preserves context
ElementWhat it does
Typed placeholdersThe model still knows whether a value is a person, account, date, or location.
Consistent within scopeThe same entity gets the same token across a request or session.
Protected mappingOriginal values stay in a controlled store, separate from the model path.
Measured qualityOriginal and redacted prompts are compared on the same tasks.

How redaction degrades answers

A model answers using the semantic structure of the prompt. Redaction that removes this structure reduces answer quality. Three properties matter most:

  • Entity type: the model needs to know whether a value is a person, account, date, or location.
  • Entity identity within a request: the same entity should be recognizable each time it appears.
  • Relationships between entities: the connections among entities must remain intact.

The goal is to keep entity type, consistency, and relationships intact when masking prompts, and to measure quality loss as an engineering requirement.

Comparing redaction and substitution techniques

Each technique in the pattern preserves a different part of the structure the model relies on.

What each technique contributes
TechniqueWhat it preservesScope or control
Typed placeholdersEntity type (person, account, date, or location).Applied to the prompt before it reaches the model.
Consistent tokensEntity identity and the relationships between entities.The same token for the same entity across a request or session.
Reversible tokenizationThe ability to restore original values in outputs.Restoration only where policy allows; mapping held in a protected store.

Securing the mapping layer

Reversible tokenization depends on a mapping between placeholders and original values. Keep that mapping in a protected store, separate from the model path, so original values are never part of what the model sees.

Restore original values in outputs only where policy allows. Restoration is a policy decision, not a default behavior.

Measuring quality before and after redaction

Treat quality loss as an engineering requirement rather than an assumption. The test is a direct comparison:

  1. Run a set of tasks on the original prompts.
  2. Run the same tasks on the redacted prompts.
  3. Compare the results to measure the quality difference.

Enforcing the policy at runtime

Enforce redaction, mapping, and restoration at the runtime layer so every application, agent, and tool call follows one policy. Consistent prompt and tool-call policy, with audit logging, keeps behavior uniform across applications and agents instead of depending on each one to implement masking on its own.

Plan redaction that holds up at runtime: one policy, applied the same way to every application, agent, and tool call.