You can check and replace Personal Identifiable Information (PII) from the /PII REST API endpoint or any of the official SDKs (Python, Go, Rust, JS, or cURL).

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
3
4from predictionguard import PredictionGuard
5
6# Set your Prediction Guard token as an environmental variable.
7os.environ["PREDICTIONGUARD_API_KEY"] = "<api key>"
8
9client = PredictionGuard()
10
11response = client.pii.check(
12 prompt="Hello, my name is John Doe and my SSN is 111-22-3333.",
13 replace=True,
14 replace_method="mask"
15)
16
17print(json.dumps(
18 response,
19 sort_keys=True,
20 indent=4,
21 separators=(',', ': ')
22))

The output will look something like:

1{
2 "checks":[
3 {
4 "new_prompt":"Hello, my name is * and my SSN is *.",
5 "index":0,
6 "status":"success"
7 }
8 ],
9 "created":"1726861992",
10 "id":"pii-qFzipirLyeEU2QJqnUavWkIKjf30BirR",
11 "object":"pii_check"
12}

This approach presents a straightforward way for readers to choose and apply the code example that best suits their needs for generating text completions using either Python, Go, Rust, JS, or cURL.