Briefing

Handling PII data in LangChain

security
Anthropic OpenAI

Mask PII before sending data to LLMs by integrating Presidio or OpaquePrompts into your chain.

What to do now

Add PresidioAnonymizer to your chain, set LANGCHAIN_HIDE_INPUTS=true, and verify that logs in LangSmith contain no PII.

Summary

The LangChain blog on 3 October 2023 discusses how to handle personally identifiable information (PII) when building LLM applications, highlighting GDPR compliance and the risks of sending raw PII to providers such as OpenAI, Anthropic, and Cohere. It introduces Microsoft Presidio as a tool that detects and anonymizes PII using rule‑based logic and NER models, replacing entities with generic placeholders or fake values via the faker library. OpaquePrompts is presented as an alternative that uses confidential computing to mask PII before sending data to the LLM and then deanonymizes the response, ensuring the original entities are preserved for the user. The article also covers how to prevent PII from being logged in LangSmith by setting LANGCHAIN_HIDE_INPUTS=true and LANGCHAIN_HIDE_OUTPUTS=true, or by masking inputs before they are sent to the chain. It explains that LangSmith can log sanitized data if the masking is applied before the chain receives the input, allowing developers to debug while keeping logs free of PII. The blog provides code snippets for integrating PresidioAnonymizer into a chain, and discusses the LLMGuard suite for input and output controls. It emphasizes the importance of reviewing provider privacy policies and suggests using the provided tools to maintain compliance and protect user data. The post concludes by encouraging teams to adopt these practices to build safe, privacy‑respecting LLM applications.

Key changes

  • Microsoft Presidio detects and anonymizes PII using rule‑based logic and NER models
  • OpaquePrompts uses confidential computing to mask PII before LLM input and deanonymizes after
  • LANGCHAIN_HIDE_INPUTS=true and LANGCHAIN_HIDE_OUTPUTS=true prevent PII from being logged in LangSmith
  • Masking before sending to the chain allows sanitized logs while preserving debugging data
  • LLMGuard suite provides input and output controls for additional safety
  • Code example shows PresidioAnonymizer integration into a LangChain chain
  • Guidance on reviewing provider privacy policies to ensure compliance
  • Encourages adoption of PII handling practices for privacy‑respecting LLM apps

Affects

internal

Customer impact

Analyzing matches…

Ask about this story

Impact on an agency? Which customers? Compare historically Risks of waiting