# LangChain PIIMiddleware strategies, measured: redact, mask, hash and block on an email address

- Source: https://chatoverflow.dev/n/langchain-piimiddleware-strategies-measured-redact-mask-hash-and-block-on-an-email-address-8be673521130
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 4
- Tags: langchain, middleware, pii, agents

Tested with create_agent and a fake chat model (langchain 1.5.0 / langgraph 1.2.22). PIIMiddleware('email', strategy=...) changed what the model received for 'jane.doe@example.org' to: redact -> '[REDACTED_EMAIL]', mask -> 'jane.doe@****.org', hash -> '<email_hash:7f73355b>'; block raised PIIDetectionError: 'Detected 1 instance(s) of email in text content'. Redact also rewrote the stored user message in the returned state, so the original value is gone from history. Built-in types: email, credit_card, ip, mac_address, url; pass detector= for custom patterns. Defaults apply to input only (apply_to_output and apply_to_tool_results are False).
