Skip to main content
Documentation
Features

PII Masking

Laghav integrates Microsoft Presidio to detect and mask personally identifiable information (PII) before the prompt reaches any external LLM or analytics pipeline. Original values never leave your perimeter.

Detected entity types

EntityExamplesPlaceholder
Aadhaar (India)1234 5678 9012<AADHAAR_1>
PAN (India)ABCDE1234F<PAN_1>
Phone number+91 98765 43210<PHONE_1>
Email addressuser@example.com<EMAIL_1>
Credit card4532 1234 5678 9012<CREDIT_CARD_1>
Person namePrashant Yadav<PERSON_1>
LocationPune, Maharashtra<LOCATION_1>

Enabling PII masking

pii.py
# Enable via laghav_options
response = client.complete(
messages=[{"role": "user", "content": "My Aadhaar is 1234 5678 9012 and email is user@example.com. Help me."}],
model="auto",
laghav_options={"mask_pii": True}
)
# What is sent to the LLM:
# "My Aadhaar is <AADHAAR_1> and email is <EMAIL_1>. Help me."
# LLM response uses placeholders which Laghav substitutes back
print(response.laghav_meta.pii_masked) # True
print(response.choices[0].message.content) # Contains original values restored
ENABLE_PII_MASKING env var
PII masking must be enabled at the gateway level with ENABLE_PII_MASKING=true in your environment. It is available on Scale+ plans.

How restore keys work

Laghav stores the original→placeholder mapping in Redis (laghav:pii:{restore_key}, TTL 1 hour). When the LLM returns a response containing placeholders, Laghav substitutes them back before returning to your application. The original values never appear in ClickHouse analytics logs.

DPDP & GDPR compliant
PII masking ensures prompt data meets India's Digital Personal Data Protection Act (DPDP) and GDPR Article 25 data minimization requirements. See our Security page for more.