user_metadata object (up to 16 top-level keys, key names up to 64 characters, nesting depth up to 3, total serialized size up to 4 KB) alongside your request-mode call. It is cached together with the PII mapping for 1 hour and is returned again in the response body when you call the endpoint in response mode with the corresponding key.
1. Example Anonymization request:
import requests
import json
import os
url = "https://api.enkryptai.com/guardrails/pii"
payload = json.dumps({
"text": "John Everyman, born on January 1, 1970, at 123 Birth Lane, Smalltown, USA, embarked on a journey filled with diverse experiences and milestones. His Social Security number, 456-45-6789, was issued in his home state, marking the beginning of his financial footprint. Here is my email: example@example.com",
"mode": "request",
"key": None,
"entities": [
"US_SSN"
]
})
headers = {
'Content-Type': 'application/json',
'apikey': os.getenv('ENKRYPTAI_API_KEY')
}
response = requests.request("POST", url, headers=headers, data=payload)
formatted_response = json.dumps(json.loads(response.text), indent=4)
print(formatted_response)
import os
from enkryptai_sdk import *
from dotenv import load_dotenv
load_dotenv()
ENKRYPT_API_KEY = os.getenv("ENKRYPTAI_API_KEY")
ENKRYPT_BASE_URL = os.getenv("ENKRYPTAI_BASE_URL") or "https://api.enkryptai.com"
pii_original_text = "John Everyman, born on January 1, 1970, at 123 Birth Lane, Smalltown, USA, embarked on a journey filled with diverse experiences and milestones. His Social Security number, 456-45-6789, was issued in his home state, marking the beginning of his financial footprint. Here is my email: example@example.com"
entities = ["US_SSN"]
redact_response = guardrails_client.pii(text=pii_original_text, mode="request", entities=entities)
# Get redacted key and text
pii_key = redact_response.key # Key for unredacting
pii_anonymized_text = redact_response.text # "My name is <PERSON_0>"
# print(pii_anonymized_text)
print(redact_response.to_dict())
Anonymization response:
JSON
{
"text": "<PERSON_0>, born on <DATE_TIME_0>, at 123 Birth Lane, <LOCATION_1>, <LOCATION_0>, embarked on a journey filled with diverse experiences and milestones. His Social Security number, <US_SSN_0>, was issued in his home state, marking the beginning of his financial footprint. Here is my email: <EMAIL_ADDRESS_0>",
"key": "e0d23d58abe14b2babb3be5aeab8250e"
}
2. Example de-anonymization request:
import requests
url = "https://api.enkryptai.com/guardrails/pii"
payload = {
"text": "<PERSON_0>, born on <DATE_TIME_0>, at 123 Birth Lane, <LOCATION_1>, <LOCATION_0>, embarked on a journey filled with diverse experiences and milestones. His Social Security number, <US_SSN_0>, was issued in his home state, marking the beginning of his financial footprint. Here is my email: <EMAIL_ADDRESS_0>",
"mode": "response",
"key": "e0d23d58abe14b2babb3be5aeab8250e"
}
headers = {
"Content-Type": "application/json",
'apikey': os.getenv('ENKRYPTAI_API_KEY')
}
response = requests.request("POST", url, json=payload, headers=headers)
formatted_response = json.dumps(json.loads(response.text), indent=4)
print(formatted_response)
unredact_response = guardrails_client.pii(text=pii_anonymized_text, mode="response", key=pii_key)
unredact_response_text = unredact_response.text
# print(unredact_response_text)
assert unredact_response_text == pii_original_text
print(unredact_response.to_dict())
De-anonymization response:
JSON
{
"text": "John Everyman, born on January 1, 1970, at 123 Birth Lane, Smalltown, USA, embarked on a journey filled with diverse experiences and milestones. His Social Security number, 456-45-6789, was issued in his home state, marking the beginning of his financial footprint. Here is my email: example@example.com",
"key": "e0d23d58abe14b2babb3be5aeab8250e"
}

