Home / Function/ test_model_retry_specific_exceptions() — langchain Function Reference

test_model_retry_specific_exceptions() — langchain Function Reference

Architecture documentation for the test_model_retry_specific_exceptions() function in test_model_retry.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  855ca11b_35ef_75fe_8b49_733aa840effe["test_model_retry_specific_exceptions()"]
  6a114635_155a_5b86_2f48_fb8ca99f7545["test_model_retry.py"]
  855ca11b_35ef_75fe_8b49_733aa840effe -->|defined in| 6a114635_155a_5b86_2f48_fb8ca99f7545
  style 855ca11b_35ef_75fe_8b49_733aa840effe fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py lines 290–319

def test_model_retry_specific_exceptions() -> None:
    """Test ModelRetryMiddleware only retries specific exception types."""
    # This model will fail with RuntimeError, which we won't retry
    model = AlwaysFailingModel(error_message="Runtime error", error_type=RuntimeError)

    # Only retry ValueError
    retry = ModelRetryMiddleware(
        max_retries=2,
        retry_on=(ValueError,),
        initial_delay=0.01,
        jitter=False,
        on_failure="continue",
    )

    agent = create_agent(
        model=model,
        tools=[],
        middleware=[retry],
        checkpointer=InMemorySaver(),
    )

    result = agent.invoke(
        {"messages": [HumanMessage("Hello")]},
        {"configurable": {"thread_id": "test"}},
    )

    ai_messages = [m for m in result["messages"] if isinstance(m, AIMessage)]
    assert len(ai_messages) >= 1
    # RuntimeError should fail immediately (1 attempt only)
    assert "1 attempt" in ai_messages[-1].content

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free