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 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.
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: 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 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 all for maximum coverage when missing PII is unacceptable
  • 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

Contact

Financial

Digital

Identity Documents

Medical / PHI

Professional