test_pii.py — langchain Source File
Architecture documentation for test_pii.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13["test_pii.py"] feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> feec1ec4_6917_867b_d228_b134d0ff8099 f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> 9444498b_8066_55c7_b3a2_1d90c4162a32 e07f6d54_afcc_052d_d33f_8ccdcc46f752["langgraph.runtime"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> e07f6d54_afcc_052d_d33f_8ccdcc46f752 d9a6942a_c37a_07f8_ed13_74d0fdc117be["langchain.agents"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> d9a6942a_c37a_07f8_ed13_74d0fdc117be 998e41c8_6a3e_eb9b_699f_db967a1242f7["langchain.agents.factory"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> 998e41c8_6a3e_eb9b_699f_db967a1242f7 6e262d57_c977_8a8b_ddbd_7efa596c2da5["langchain.agents.middleware.pii"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> 6e262d57_c977_8a8b_ddbd_7efa596c2da5 069947d2_727b_035a_0691_c12203e2f5a6["tests.unit_tests.agents.model"] 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 --> 069947d2_727b_035a_0691_c12203e2f5a6 style 6dcffc03_fae9_01f8_ed9b_d30d8a73dd13 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Tests for PII detection middleware."""
from typing import Any
import pytest
from langchain_core.messages import AIMessage, HumanMessage, ToolCall, ToolMessage
from langgraph.runtime import Runtime
from langchain.agents import AgentState
from langchain.agents.factory import create_agent
from langchain.agents.middleware.pii import (
PIIDetectionError,
PIIMatch,
PIIMiddleware,
detect_credit_card,
detect_email,
detect_ip,
detect_mac_address,
detect_url,
)
from tests.unit_tests.agents.model import FakeToolCallingModel
# ============================================================================
# Detection Function Tests
# ============================================================================
class TestEmailDetection:
"""Test email detection."""
def test_detect_valid_email(self) -> None:
content = "Contact me at john.doe@example.com for more info."
matches = detect_email(content)
assert len(matches) == 1
assert matches[0]["type"] == "email"
assert matches[0]["value"] == "john.doe@example.com"
assert matches[0]["start"] == 14
assert matches[0]["end"] == 34
def test_detect_multiple_emails(self) -> None:
content = "Email alice@test.com or bob@company.org"
matches = detect_email(content)
assert len(matches) == 2
assert matches[0]["value"] == "alice@test.com"
assert matches[1]["value"] == "bob@company.org"
def test_no_email(self) -> None:
content = "This text has no email addresses."
matches = detect_email(content)
assert len(matches) == 0
def test_invalid_email_format(self) -> None:
content = "Invalid emails: @test.com, user@, user@domain"
matches = detect_email(content)
# Should not match invalid formats
assert len(matches) == 0
// ... (587 more lines)
Domain
Subdomains
Classes
Dependencies
- langchain.agents
- langchain.agents.factory
- langchain.agents.middleware.pii
- langchain_core.messages
- langgraph.runtime
- pytest
- tests.unit_tests.agents.model
- typing
Source
Frequently Asked Questions
What does test_pii.py do?
test_pii.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What does test_pii.py depend on?
test_pii.py imports 8 module(s): langchain.agents, langchain.agents.factory, langchain.agents.middleware.pii, langchain_core.messages, langgraph.runtime, pytest, tests.unit_tests.agents.model, typing.
Where is test_pii.py in the architecture?
test_pii.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/implementations).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free