Open in Google Colab
Run this exact tutorial interactively in Google Colab
DataFramer SDK β PII/PHI Anonymization
In this notebook we will demonstrate how the DataFramer Python SDK (PIP Package:pydataframer) can be used to detect and mask Personally Identifiable Information (PII) and Protected Health Information (PHI) in your datasets.
We will walk through the complete anonymization workflow:
- Upload a seed dataset containing sensitive data
- Create an anonymization run to detect and mask PII/PHI entities
- Inspect the masked output sample by sample
- Download all anonymized files as a ZIP archive
PII-M1 model (pii_m1) as the default and recommended detection method for high-accuracy detection across names, emails, phone numbers, SSNs, dates of birth, and more.
Step 1: Install and Setup SDK
Install the DataFramer SDK and additional utilities.DATAFRAMER_API_KEY.
Step 2: Create Sample Dataset
We build a small synthetic CSV in-memory β no external files required. Each row is a fictitious patient support record containing PII/PHI fields that the anonymization run will detect and mask.Step 3: Upload the Dataset
Wrap the synthetic CSV in a ZIP buffer and upload it as a seed dataset. If a dataset with the same name already exists it is reused (idempotent).Step 4: Create an Anonymization Run
Create an anonymization run that will scan every row in the dataset and replace detected entities with masked tokens. Detection method:pii_m1 β the recommended setting. Uses the PII-M1 neural model for high precision and recall.
PII types targeted (see the full entity catalogue):
Step 5: Poll Until Run Completes
The anonymization run executes asynchronously. We poll every 10 seconds until it reachesSUCCEEDED or FAILED.
Step 6: List All Anonymization Runs
Retrieve all anonymization runs for your company account (newest first). Useful for auditing past anonymization runs.Step 7: Retrieve Full Run Details
Fetch the complete run record including dataset metadata, configuration parameters, and timing information.Step 8: Inspect Masked Sample Content
Download each anonymized file and display a preview. Entity counts come from the runβsresults (retrieved in the previous step).
Step 9: Download All Anonymized Files as ZIP
Retrieve a presigned URL and download all anonymized files as a single ZIP archive. The URL is valid for 1 hour.Results
Entity detection summary across all files.Whatβs Next?
- Adjust
pii_types: add or remove entity types from the full catalogue to target exactly the entities relevant to your use case - Try a different
detection_method: switch toallfor maximum coverage when missing PII is unacceptable - Use your own data: replace the synthetic CSV with a real dataset via
create_with_filesorcreate_from_zip - Scale up: the same workflow supports
MULTI_FILEandMULTI_FOLDERdatasets β pass multiple file handles or usedataset_type="MULTI_FOLDER"withfolder_names - Integrate downstream: the anonymized ZIP can be stored in S3, fed into further processing pipelines, or used as safe input to your LLM workflows
Folder Generation
Generate multi-file synthetic datasets from seed data
API Reference
Full endpoint documentation
Appendix: Available PII/PHI Types
Pass any combination of the keys below as thepii_types argument when creating an anonymization run. Each key maps to a default mask token shown in the Masked as column.

