Skip to main content

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
The anonymization pipeline uses the AIMon-PII-M1 model combined with heuristic rules (aimon_pii_m1+heuristics) 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.
A Dataframer API key is required. Retrieve yours from Account β†’ Keys β†’ Copy API Key on the web application and add it as a Colab secret named 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: aimon_pii_m1+heuristics β€” the recommended setting. Combines the AIMon-PII-M1 neural model with regex-based heuristic rules for high precision and recall. PII types targeted (see the full entity catalogue):
CategoryEntity types
Personalfirst_name, last_name, date_of_birth
Contactemail, phone_number, street_address
Financialssn

Step 5: Poll Until Run Completes

The anonymization run executes asynchronously. We poll every 10 seconds until it reaches SUCCEEDED 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’s results (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 to heuristics for faster runs, or all for maximum coverage
  • Use your own data: replace the synthetic CSV with a real dataset via create_with_files or create_from_zip
  • Scale up: the same workflow supports MULTI_FILE and MULTI_FOLDER datasets β€” pass multiple file handles or use dataset_type="MULTI_FOLDER" with folder_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 the pii_types argument when creating an anonymization run. Each key maps to a default mask token shown in the Masked as column.

Personal

KeyMasked as
first_name<FIRST NAME>
last_name<LAST NAME>
date_of_birth<DOB>
date<DATE>
age<AGE>
gender<GENDER>
nationality<NATIONALITY>
race_ethnicity<RACE ETHNICITY>
marital_status<MARITAL STATUS>

Contact

KeyMasked as
email<EMAIL>
phone_number<PHONE>
street_address<ADDRESS>
postcode<ZIP>
city<CITY>
state<STATE>
country<COUNTRY>

Financial

KeyMasked as
ssn<SSN>
credit_debit_card<CREDIT CARD>
bank_routing_number<BANK ROUTING>
routing_number<ROUTING>
tax_id<TAX ID>
iban<IBAN>

Digital

KeyMasked as
ipv4<IP ADDRESS>
url<URL>
user_name<USERNAME>
password<PASSWORD>
mac_address<MAC ADDRESS>
device_identifier<DEVICE ID>

Identity Documents

KeyMasked as
passport_number<PASSPORT>
certificate_license_number<LICENSE>
national_id<NATIONAL ID>
voter_id<VOTER ID>

Medical / PHI

KeyMasked as
medical_record_number<MRN>
diagnosis<DIAGNOSIS>
medication<MEDICATION>
health_plan_beneficiary_number<HEALTH PLAN>
patient_id<PATIENT ID>
lab_result<LAB RESULT>

Professional

KeyMasked as
company_name<COMPANY>
occupation<OCCUPATION>
employee_id<EMPLOYEE ID>
salary<SALARY>