DEV Community

Cover image for Redact PII Before Sending Data to LLMs: A Developer's Guide
Raviteja Nekkalapu
Raviteja Nekkalapu

Posted on

Redact PII Before Sending Data to LLMs: A Developer's Guide

Why every AI integration needs PII redaction and how to implement it in 60 seconds

The AI Privacy Problem Nobody Talks About

You're building a ChatGPT wrapper or any other AI wrapper. Users submit questions.

Those questions contain:

  • Emails
  • Phone numbers
  • Social security numbers (yes, really)
  • Credit card numbers (users paste them)
  • Home addresses

All of it goes directly to OpenAI's servers.

Question: Does your privacy policy say "We share user data with third parties"?

Probably not. But you just did.

The Lawsuit Waiting to Happen

GDPR fines in 2024: €2.1 billion

Average data breach lawsuit settlement: $3.8 million

SEC now requires disclosure of AI related data handling.

It's not paranoia. It's risk management.

The Simple Fix

Redact PII before sending to the LLM.

User Input: "My SSN is 123-45-6789 and email is john@company.com"
     ↓
PII Firewall Edge
     ↓
Clean Input: "My SSN is [SSN] and email is [EMAIL]"
     ↓
Send to ChatGPT
Enter fullscreen mode Exit fullscreen mode

ChatGPT never sees the actual PII. Your liability drops to near zero.

Implementation (60 seconds)

Step 1: Get API Key

Sign up on RapidAPI (free tier available)

Step 2: Call Before LLM

async function sanitizeForLLM(userInput) {
  const response = await fetch(
    'https://pii-firewall-edge.p.rapidapi.com/v1/redact/fast',
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-RapidAPI-Key': process.env.RAPIDAPI_KEY
      },
      body: JSON.stringify({ text: userInput })
    }
  );

  const { redacted } = await response.json();
  return redacted;
}

// Usage
const cleanInput = await sanitizeForLLM(userMessage);
const aiResponse = await openai.chat.completions.create({
  messages: [{ role: 'user', content: cleanInput }]
});
Enter fullscreen mode Exit fullscreen mode

Step 3: There is no Step 3

Seriously. That's it.

What Gets Detected

Category Types Examples
Contact Info Email, Phone john@test.com, 555-1234
Government IDs SSN, Passport 123-45-6789, AB1234567
Financial Credit Card, IBAN 4111-1111-1111-1111
Healthcare NPI, Medicare 1234567890
Developer API Keys sk_live_xxx, ghp_xxx

Total: 152 PII types across 50+ countries.

Why Not Build It Yourself?

I tried. Here's what happened:

Week 1: Basic regex for SSN and email. "This is easy!"

Week 2: User submits Indian Aadhaar number. Regex fails. We used dictionary lookups and proximity patterns, not just regex

Week 3: Added 15 more patterns. Performance tanked.

Week 4: Discovered Luhn checksum. Realized I was matching fake credit cards.

Month 2: Still finding edge cases (international phone formats, API keys, crypto addresses...)

Month 8: Finally production-ready. 2,000+ lines of code. 30+ checksum validators.

You can spend 8+ months on this and then few more months in implementing enterprise grade security and then optimizing algorithms for performance

Or use PII Firewall Edge API and ship today.

Performance

Endpoint Latency Use Case
/fast 2-5ms Logs, real-time
/deep 5-15ms Context-heavy data (Addresses, Names)

The Zero-AI Advantage

"Privacy" APIs that use ML models to detect PII:

Your Data → Their AI Server → Model Training → ???
Enter fullscreen mode Exit fullscreen mode

PII Firewall Edge:

Your Data → Cloudflare Edge → Regex + Checksums → Deleted
Enter fullscreen mode Exit fullscreen mode

No AI. No logs. No training. No liability.
We run on stateless Cloudflare Workers. No database is connected to the processing pipeline. The code is ephemeral.

Pricing Reality

Provider Monthly Cost
AWS Comprehend $250+
Google DLP $200+
Private AI $500+
PII Firewall Edge $5

Same security. 97% less cost.

Get Started

Free: 500 requests/month
Pro: $5/month (5,000 requests/month)

curl -X POST "https://pii-firewall-edge.p.rapidapi.com/v1/redact/fast" \
  -H "Content-Type: application/json" \
  -H "X-RapidAPI-Key: YOUR_KEY" \
  -d '{"text": "test@example.com 123-45-6789"}'
Enter fullscreen mode Exit fullscreen mode

Try it for free - PII Firewall Edge
SDK Docs - PII Firewall Edge - SDKs


Building AI features? Don't leak user data. Start protecting your users today.

Top comments (12)

Collapse
 
sloan profile image
Sloan the DEV Moderator

We loved your post so we shared it on social.

Keep up the great work!

Collapse
 
raviteja_nekkalapu_ profile image
Raviteja Nekkalapu

Wow, thank you for featuring my article! ❤️

Super grateful to the DEV community for amplifying this important topic. Redacting PII before it hits any LLM is becoming essential.
Hope it helps lots of devs build safer AI flows!

Collapse
 
yogesh_v profile image
Yogesh

Totally relatable. I saw one of my colleague simply copy pasting complete error logs directly to Chatgpt without even a second thought to get immediate solution to the issue and thereby giving away lot of sensitive user info logged.

Collapse
 
raviteja_nekkalapu_ profile image
Raviteja Nekkalapu

Exactly ! This is the core of the issue we are trying to address.

Collapse
 
toddpress profile image
Todd Pressley

Ubiquitous problem. Brilliant business proposition!

Collapse
 
raviteja_nekkalapu_ profile image
Raviteja Nekkalapu

Thank you so much! 🙏
PII leaking into LLM providers is a silent risk that most teams only discover after it's too late. Glad this resonated with you. If you ever try the API, I'd love to hear your feedback!

Collapse
 
another_dev_ profile image
another_dev

Looks like a important problem to solve! I wonder if a visual side by side input vs output might help website visitors visualize your product.

Collapse
 
raviteja_nekkalapu_ profile image
Raviteja Nekkalapu

It's actually live here - See PII detection in action where you can see the demo which actually runs in the browser

Collapse
 
vivan_harsha profile image
Vivan

We tried it and started using it in our workflow. So far it has been good in redacting the PII. Much needed one with all the AI chaos going on everywhere

Collapse
 
raviteja_nekkalapu_ profile image
Raviteja Nekkalapu

Much needed feedback. Thanks for sharing.

Collapse
 
abhinav_gade profile image
Abhinav

The project is great, honestly. Great value with developer friendly pricing. Will definitely try it.

Collapse
 
raviteja_nekkalapu_ profile image
Raviteja Nekkalapu

Thanks. You won't regret the decision. Open to feedback !