Home / Function/ test_apply_to_both() — langchain Function Reference

test_apply_to_both() — langchain Function Reference

Architecture documentation for the test_apply_to_both() function in test_pii.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  996e9157_5e22_ce83_4ef7_c9f4cc02a1f1["test_apply_to_both()"]
  74acad26_e3cd_8385_fcb7_9bf787fa3f4a["TestPIIMiddlewareIntegration"]
  996e9157_5e22_ce83_4ef7_c9f4cc02a1f1 -->|defined in| 74acad26_e3cd_8385_fcb7_9bf787fa3f4a
  style 996e9157_5e22_ce83_4ef7_c9f4cc02a1f1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py lines 391–405

    def test_apply_to_both(self) -> None:
        """Test that middleware processes both input and output."""
        middleware = PIIMiddleware(
            "email", strategy="redact", apply_to_input=True, apply_to_output=True
        )

        # Should process HumanMessage
        state = AgentState[Any](messages=[HumanMessage("Email: test@example.com")])
        result = middleware.before_model(state, Runtime())
        assert result is not None

        # Should process AIMessage
        state = AgentState[Any](messages=[AIMessage("My email is ai@example.com")])
        result = middleware.after_model(state, Runtime())
        assert result is not None

Domain

Subdomains

Frequently Asked Questions

What does test_apply_to_both() do?
test_apply_to_both() 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_both() defined?
test_apply_to_both() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_pii.py at line 391.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free