PII modification

PII anonymization

Some of your incoming prompts may include personally identifiable information (PII). With Prediction Guard's PII anonymization feature, you can detect PII such as names, email addresses, phone numbers, credit card details, and country-specific ID numbers like SSNs, NHS numbers, and passport numbers. Here's a demonstration of how this works:

import os
import json
 
import predictionguard as pg
 
os.environ['PREDICTIONGUARD_TOKEN'] = "<your access token>"
 
result = pg.PII.check(
    prompt="Hello, my name is John Doe and my SSN is 111-22-3333",
    replace=False
)
 
print(json.dumps(
    result,
    sort_keys=True,
    indent=4,
    separators=(',', ': ')
))

This outputs the PII entity and indices of where the info was found:

{
  "checks": [
    {
      "pii_types_and_positions": "[{\"start\": 17, \"end\": 25, \"type\": \"PERSON\"}, {\"start\": 40, \"end\": 51, \"type\": \"US_SSN\"}]",
      "index": 0,
      "status": "success"
    }
  ],
  "created": 1701721456,
  "id": "pii-O0CdxbefFwSRo7uypla7hdUka3pPf",
  "object": "pii_check"
}

To maintain utility without compromising privacy, you have the option to replace PII with fake names and then forward the modified prompt to the LLM for further processing:

result = pg.PII.check(
    prompt="Hello, my name is John Doe and my SSN is 111-22-3333",
    replace=True,
    replace_method="fake"
)
 
print(json.dumps(
    result,
    sort_keys=True,
    indent=4,
    separators=(',', ': ')
))

The processed prompt will then be:

{
  "checks": [
    {
      "new_prompt": "Hello, my name is William and my SSN is 222-33-4444",
      "index": 0,
      "status": "success"
    }
  ],
  "created": 1701721456,
  "id": "pii-O0CdxbefFwSRo7uypla7hdUka3pPf",
  "object": "pii_check"
}

Other options for the replace_method parameter include: random (to replace the detected PII with random character), category (to mask the PII with the entity type) and mask (simply replace with *).