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.
| Element | What it does |
|---|---|
| Typed placeholders | The model still knows whether a value is a person, account, date, or location. |
| Consistent within scope | The same entity gets the same token across a request or session. |
| Protected mapping | Original values stay in a controlled store, separate from the model path. |
| Measured quality | Original 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.
| Technique | What it preserves | Scope or control |
|---|---|---|
| Typed placeholders | Entity type (person, account, date, or location). | Applied to the prompt before it reaches the model. |
| Consistent tokens | Entity identity and the relationships between entities. | The same token for the same entity across a request or session. |
| Reversible tokenization | The 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:
- Run a set of tasks on the original prompts.
- Run the same tasks on the redacted prompts.
- 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.