Skip to main content

PII API Endpoint

Open In Colab

Personally Identifiable Information (PII) is any private data that could lead to the identification of an individual.

This detector is designed to catch all PII instances to ensure that your data stays confidential and is not exposed to third-party, i.e. LLMs.

tip

Generate API key from the ZenGuard Console.

API Endpoint

This is the generally available endpoint for PII detection.

https://api.zenguard.ai/v1/detect/pii

For the enterprise-grade customers we offer a dedicated endpoint.

Policies

Using PII Detector policy you can enable or disable the detection of the following PII types:

  • Name: The individual's full name or any part that could identify the individual.
  • Email: An individual's email address.
  • Phone: Telephone numbers associated with an individual.
  • Address: Physical address information, including residential, business, or mailing addresses.
  • Credit Card: Credit card numbers that could be used for financial fraud.
  • SSN: Social Security Numbers, a unique number assigned to U.S. citizens for tracking social security benefits and for other identification purposes.
  • Location: Geographical information that can pinpoint the location of an individual.
  • IP Address: A unique address that identifies a device on the Internet or a local network, which can be traced back to an individual.
  • UUID: Universally Unique Identifier

Also, you can select the redact action if the PII entity is detected.

PII Redact Type

  • Marker: the PII entity is replaced with its marker. Example: John Snow -> NAME_1
  • Mask: the PII entity is hidden with the mask. Example: 1234-5679-1234-1234 -> *******************

API

Example:

import os
import requests

prompt = "My credit card number is 1234-5679-1234-1234 and my name is John Smith."
session = requests.Session()

response = session.post(
"https://api.zenguard.ai/v1/detect/pii",
json={"messages": [prompt]},
headers={"x-api-key": os.getenv("ZEN_API_KEY")}
)

if response.json()["is_detected"]:
print("PII detected. ZenGuard: 1, big brother: 0.")
else:
print("No PII detected: your data is safe to feed into any LLM.")

assert response.json()["is_detected"], "Error detecting pii"

Response Example:

 {
"is_detected": true,
"score": 1.0,
"latency": 19.84665700001642,
"extra": {
"sanitized_message": "My credit card number is CREDIT_CARD_1 and my name is NAME_1.",
"detected_pii": [
{
"text": "John Smith",
"type": "name"
},
{
"text": "1234-5679-1234-1234",
"type": "credit_card"
}
]
}
}
  • is_detected(boolean): Indicates whether the prompt contains any PII entities. In this example, it is True since the prompt contains credit card information and name.

  • score(float: 0.0 - 1.0): The confidence level of the PII entity detection.

  • latency(float): The server-side latency in ms.

  • sanitized_message(string or null): Contains the prompt redacted in accordance to the Policy. In this case, the prompt was redacting using Markers.

  • detected_pii(list): A list of detected PII entities and their types.

Error Codes:

    - 401 Unauthorized: API key is missing or invalid.
- 400 Bad Request: Request body is malformed.
- 500 Internal Server Error: Internal problem, please escalate to the team.

Client

Also, you can use ZenGuard Python Client to detect PII entities.

Example:

import os
from zenguard import Credentials, Detector, ZenGuard, ZenGuardConfig

api_key = os.environ.get("ZEN_API_KEY")
config = ZenGuardConfig(credentials=Credentials(api_key=api_key))
zenguard = ZenGuard(config=config)

message="My credit card number is 1234-5679-1234-1234 and my name is John Smith."
response = zenguard.detect(detectors=[Detector.PII], prompt=message)
if response.get("is_detected"):
print("PII detected. ZenGuard: 1, big brother: 0.")
else:
print("No PII detected: your data is safe to feed into any LLM.")

assert response.get("is_detected"), "Error detecting pii"