Join our Newsletter — 33% off our NHI Course
Home› FAQ› Cyber Security› What is the difference between format-preserving masking and…
Cyber Security

What is the difference between format-preserving masking and context-preserving rewrite?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 22, 2026 Domain: Cyber Security

Format-preserving masking keeps the shape of a value so downstream systems can still parse or validate it, while context-preserving rewrite changes the text itself to remove sensitive meaning embedded in relationships or narrative detail. Use the former for structured fields and the latter when the risk sits in the sentence, not just the value.

How the two approaches differ in practice

Format-preserving masking is about keeping a field usable while reducing exposure. The output still looks like the original data type, length, or character pattern, so downstream systems can sort, validate, or route it without rework. Context-preserving rewrite is about changing the meaning-bearing text around the value, so the sentence no longer reveals sensitive relationships, roles, timing, or intent.

The distinction matters because the same record can contain both kinds of sensitivity. A card number, account ID, or policy code may need a shape-preserving treatment, while a narrative note, support ticket, or log line may need rewriting because the sensitive detail is in the story itself. For broader guidance on masking, tokenisation, and when shape-preserving techniques are appropriate, see the Tokenisation and Data Masking Guide.

Where format-preserving masking is the better fit

Use format-preserving masking when the main requirement is compatibility with a structured system. Typical examples are payment references, identifiers, dates, telephone numbers, or codes that must still pass a schema check, checksum, or downstream parser. The goal is to suppress the original secret or personal value without breaking workflow automation, reconciliation, or test data pipelines.

This approach is strongest when consumers care about structure more than meaning. It is common in application testing, analytics feeds, and controlled sharing where the receiving system only needs a syntactically valid placeholder. The trade-off is that preserving shape can also preserve some analytic utility for an attacker, so the masking rule must be strong enough that the original value cannot be inferred from pattern, prefix, or repeated use.

Shape-preserving controls sit alongside encryption rather than replacing it. If the underlying object is still sensitive at rest or in transit, masking only limits what appears in the exposed copy. For the adjacent control family around encryption and protected storage, the Encryption Guide is the better companion reference.

Where context-preserving rewrite is the better fit

Use context-preserving rewrite when the sensitive part is not a single field but the surrounding narrative. This is common in incident reports, customer correspondence, case notes, chat transcripts, meeting summaries, or AI-generated summaries where names, relationships, locations, or timing can reveal more than any isolated identifier. In these cases, masking a token or code is not enough because the sentence still discloses the operational reality.

Rewrite works by preserving the useful intent of the text while removing or generalising the sensitive facts. That may mean replacing named relationships with role-based language, collapsing exact timing into a range, or stripping operational clues that would let a reader reconstruct the underlying event. The important judgment is whether the rewritten text still supports the business purpose without exposing the original context.

For practitioner teams, the choice is often between usability and disclosure. A rewritten sentence may be less precise, but it is often the only safe option when the meaning is distributed across multiple clauses. That makes rewrite especially relevant for review workflows, human-readable exports, and AI-assisted summarisation where the risk comes from the full context, not just one value.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS and NIST SP 800-53 Rev 5 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.

FrameworkControl / ReferenceRelevance
OWASP ASVSV14 — Data ProtectionCovers protecting sensitive data while preserving required application behaviour.
Recommendation — Apply V14 controls to limit exposure of sensitive values in stored and displayed data.
NIST SP 800-53 Rev 5SC-28 — Protection of Information at RestRelevant when masked values still need protection in storage or backups.
Recommendation — Use SC-28 to protect stored sensitive data even after masking or token substitution.
ISO/IEC 27001:2022A.8.12 — Data leakage preventionApplies to controlling disclosure in structured records and narrative content.
Recommendation — Implement A.8.12 to reduce unintended disclosure in exported or shared data.

Practitioner Guidance

What to prioritise: Classify the data first by how it is consumed. If the receiver needs a valid field shape, favour format-preserving masking; if the receiver needs the narrative but not the original detail, favour context-preserving rewrite.

What to verify: Confirm that the downstream system actually depends on the original structure before choosing a shape-preserving method. If the system only needs display or review text, a rewrite is usually safer than a masked replica that still hints at the original value.

Common mistake: Teams often apply masking to a sentence and assume the risk is solved. If the sensitive meaning lives in the relationships, sequence, or surrounding clauses, the field may be protected while the disclosure remains intact.

Practitioner takeaway: Preserve structure when machine handling matters, preserve meaning by rewriting when human or model readers could reconstruct sensitive context from the prose itself.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 22, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org