> ## Documentation Index
> Fetch the complete documentation index at: https://docs.enkryptai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PII Anonymization

Anonymizes the request text and de-anonymizes the response text.

## 1. Example Anonymization request:

<CodeGroup>
  ```python Python theme={"system"}
  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)
  ```

  ```python Python SDK theme={"system"}
  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())
  ```
</CodeGroup>

## Anonymization response:

```json JSON theme={"system"}
{
  "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:

<CodeGroup>
  ```python Python theme={"system"}
  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)
  ```

  ```python Python SDK theme={"system"}
  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())
  ```
</CodeGroup>

## De-anonymization response:

```json JSON theme={"system"}
{
  "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"
}
```
