The Flow
Step 1. Run Sensitivity Detection
This is the same detection job used in Protect Sensitive Data. Pick the classifiers whose matched values you want to mask, not the rollup tags: rollup tags likePII (Personally Identifiable Information) resolve to true/false and carry no literal value to redact.
Step 2. Read Back the Matched Values
When a sensitivity tag has no fixed set ofavailable_values, the matched text itself becomes the tag’s value. Collect those values per file.
Step 3. Mask the Matched Values
This part is plain Python, nothing Deasy-specific. Replace the longest values first, so a short match inside a longer one (an area code inside a full phone number, for instance) does not leave a partial value behind.Step 4. Mask Before You Prompt
Pull the document’s own text through the SDK rather than re-reading it from the source yourself.document_text returns each file’s content keyed by node, since a file is chunked into nodes for retrieval.
A Worked Example
Say the source file is a support ticket short enough to be a single node. This is the textdocument_text returns for it, before any masking:
matches_by_file["ticket-4821.txt"] holds the literal values the classification job found in that file:
redact(text, matches_by_file["ticket-4821.txt"]) from Step 3 on that node’s text produces:
How to Use This
- For inline masking, not exclusion. Use this when a document is mostly fine to share and only specific values need to be hidden. To keep a whole file out of AI systems, gate a slice instead, as in Protect Sensitive Data.
- Pick literal-value tags. Only classifiers without a fixed
available_valueslist return the matched text as their value. Rollup tags (PII,PCI,PHI) are booleans and have nothing to replace. - Re-run after re-classification. Matched values reflect the last classification job. If the source document changes, re-run detection before trusting the redaction.
Next Steps
Protect Sensitive Data
Gate an entire slice on sensitivity tags instead of masking inline.
Precision Patterns for Sensitive Data
Add custom identifiers to the sensitivity catalog before you redact them.
Metadata
How tag values and evidence are stored per file.
Prepare an AI-Ready Dataset
Combine masking with the quality dimensions of the AI-ready gate.
