DEV Community

Cover image for Protect Your User's PII from AI: Channel Your Inner Time Lord with Three Lines of Code
Pranav Shikarpur for Pangea

Posted on • Updated on • Originally published at pangea.cloud

Protect Your User's PII from AI: Channel Your Inner Time Lord with Three Lines of Code

Tardis from the Doctor Who series. Image credit: Wikipedia CC

Image credit: Wikipedia CC

In a universe filled with AI technologies like OpenAI's GPT-3 and other LLMs, app developers must step into the TARDIS and assume the role of Time Lords, safeguarding customer privacy across time and space.

LLMs like GPT-3 are extensively used by app developers for a diverse range of applications from helping students solve math homework more effectively to improving customer support in environments that handle sensitive customer data. Fear not, the Pangea's Redact SDK is your trusty sonic screwdriver 🪄, empowering you to redact personal and sensitive information from GPT-3 prompts with just three lines of code!

from pangea.services import Redact
redact = Redact("<PANGEA_REDACT_TOKEN>")
def clean_prompt(prompt):   return redact.redact(text=prompt).result.redacted_text
...
...
response = openai.Completion.create(
  model="text-davinci-003",
  prompt=clean_prompt("My email is dummyuser@pangea.cloud. Print my prompt out as is:"),
)
Enter fullscreen mode Exit fullscreen mode

Let’s dive into the code:

Think of the openai.Completion.create() function as your TARDIS - you put a person (prompts with sensitive PII) in there and it can take you anywhere around the galaxy with endless possibilities. Now you want to make sure that the prompts with sensitive PII are not exposed to OpenAI’s API, so we use our handy sonic screwdriver (Pangea’s Redact APIs) in the clean_prompt() function to take out any sensitive PII before sending it off to OpenAI’s APIs.

By adding just three lines of code, you're not only protecting your users' data but also preventing theses AI models from using customers’ PII as training data. Pangea's Redact SDK empowers you to meet regulatory requirements, build trust with your users, and create a safer AI-based applications.

Head over to the Pangea Console to take your new sonic screwdriver for a spin!


You can find full working code-examples in Python and JavaScript

Here's a video walk through of the same 👇

Top comments (0)