Skip to content

Commit 30f7c87

Browse files
authored
feat(langchain_v1): Implement PIIMiddleware (#33271)
- supports 6 well-known PII types (email, credit_card, ip, mac_address, url) - 4 handling strategies (block, redact, mask, hash) - supports custom PII types with detector functions or regex - the built-in types were chosen because they are common, and detection can be reliably implemented with stdlib
1 parent fdf8181 commit 30f7c87

File tree

4 files changed

+1405
-0
lines changed

4 files changed

+1405
-0
lines changed

.claude/settings.local.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"allow": [
44
"Bash(uv run:*)",
55
"Bash(make:*)"
6+
"WebSearch",
7+
"WebFetch(domain:ai.pydantic.dev)",
8+
"WebFetch(domain:openai.github.io)",
9+
"Bash(uv run:*)",
10+
"Bash(python3:*)"
611
],
712
"deny": [],
813
"ask": []

libs/langchain_v1/langchain/agents/middleware/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Middleware plugins for agents."""
22

33
from .human_in_the_loop import HumanInTheLoopMiddleware
4+
from .pii import PIIDetectionError, PIIMiddleware
45
from .planning import PlanningMiddleware
56
from .prompt_caching import AnthropicPromptCachingMiddleware
67
from .summarization import SummarizationMiddleware
@@ -23,6 +24,8 @@
2324
"AnthropicPromptCachingMiddleware",
2425
"HumanInTheLoopMiddleware",
2526
"ModelRequest",
27+
"PIIDetectionError",
28+
"PIIMiddleware",
2629
"PlanningMiddleware",
2730
"SummarizationMiddleware",
2831
"ToolCallLimitMiddleware",

0 commit comments

Comments
 (0)