Home / Function/ test_middleware_error_behavior() — langchain Function Reference

test_middleware_error_behavior() — langchain Function Reference

Architecture documentation for the test_middleware_error_behavior() function in test_tool_call_limit.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ea6a4c5a_8c34_449a_3d87_119c595a2747["test_middleware_error_behavior()"]
  a75b8390_08d3_7137_c8a7_9d78fc0c4517["test_tool_call_limit.py"]
  ea6a4c5a_8c34_449a_3d87_119c595a2747 -->|defined in| a75b8390_08d3_7137_c8a7_9d78fc0c4517
  style ea6a4c5a_8c34_449a_3d87_119c595a2747 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py lines 228–252

def test_middleware_error_behavior() -> None:
    """Test middleware error behavior.

    Test that middleware raises ToolCallLimitExceededError when configured with
    exit_behavior='error'.
    """
    middleware = ToolCallLimitMiddleware(thread_limit=2, exit_behavior="error")
    runtime = None

    state = ToolCallLimitState(
        messages=[AIMessage("Response", tool_calls=[{"name": "search", "args": {}, "id": "1"}])],
        thread_tool_call_count={"__all__": 2},
        run_tool_call_count={"__all__": 2},
    )

    with pytest.raises(ToolCallLimitExceededError) as exc_info:
        middleware.after_model(state, runtime)  # type: ignore[arg-type]

    error = exc_info.value
    # Thread count in error message shows hypothetical count (what it would have been)
    assert error.thread_count == 3
    assert error.thread_limit == 2
    # Run count includes the blocked call
    assert error.run_count == 3
    assert error.tool_name is None

Domain

Subdomains

Frequently Asked Questions

What does test_middleware_error_behavior() do?
test_middleware_error_behavior() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py.
Where is test_middleware_error_behavior() defined?
test_middleware_error_behavior() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_tool_call_limit.py at line 228.

Analyze Your Own Codebase

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

Try Supermodel Free