You can check and replace Personal Identifiable Information (PII) from the /PII endpoint or PII class in the Python Client. This endpoint/Class takes three parameters:

  • prompt - The prompt that you want to check for PII.
  • replace - A boolean for replacing the PII if any is found.
  • replace_method - The method you would like to use to replace any found PII. The methods are random, mask, category, and fake.

The output will include the replaced PII if any is present, or will tell you if any PII is in the prompt if replace is not chosen.

Check and Replace PII

To check and replace PII, you can use the following code examples. Depending on your preference or requirements, select the appropriate method for your application.

1import os
2import json
4import predictionguard as pg
6# Set your Prediction Guard token as an environmental variable.
7os.environ["PREDICTIONGUARD_TOKEN"] = "<your access token>"
9response = pg.PII.check(
10 prompt="Hello, my name is John Doe and my SSN is 111-22-3333.",
11 replace=False
15 response,
16 sort_keys=True,
17 indent=4,
18 separators=(',', ': ')

This approach provides a straightforward way for readers to choose and apply the code example that best suits their needs for checking and replacing PII using either Python or cURL.