test_apply_to_tool_results() — langchain Function Reference
Architecture documentation for the test_apply_to_tool_results() function in test_pii.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e26537eb_1a70_dfc2_feae_9d059b92f641["test_apply_to_tool_results()"] 74acad26_e3cd_8385_fcb7_9bf787fa3f4a["TestPIIMiddlewareIntegration"] e26537eb_1a70_dfc2_feae_9d059b92f641 -->|defined in| 74acad26_e3cd_8385_fcb7_9bf787fa3f4a style e26537eb_1a70_dfc2_feae_9d059b92f641 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py lines 423–448
def test_apply_to_tool_results(self) -> None:
"""Test that middleware processes tool results when enabled."""
middleware = PIIMiddleware(
"email", strategy="redact", apply_to_input=False, apply_to_tool_results=True
)
# Simulate a conversation with tool call and result containing PII
state = AgentState[Any](
messages=[
HumanMessage("Search for John"),
AIMessage(
content="",
tool_calls=[ToolCall(name="search", args={}, id="call_123", type="tool_call")],
),
ToolMessage(content="Found: john@example.com", tool_call_id="call_123"),
]
)
result = middleware.before_model(state, Runtime())
assert result is not None
# Check that the tool message was redacted
tool_msg = result["messages"][2]
assert isinstance(tool_msg, ToolMessage)
assert "[REDACTED_EMAIL]" in tool_msg.content
assert "john@example.com" not in tool_msg.content
Domain
Subdomains
Source
Frequently Asked Questions
What does test_apply_to_tool_results() do?
test_apply_to_tool_results() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py.
Where is test_apply_to_tool_results() defined?
test_apply_to_tool_results() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py at line 423.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free