Home / Function/ test_model_retry_custom_failure_formatter() — langchain Function Reference

test_model_retry_custom_failure_formatter() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py lines 229–258

def test_model_retry_custom_failure_formatter() -> None:
    """Test ModelRetryMiddleware with custom failure message formatter."""

    def custom_formatter(exc: Exception) -> str:
        return f"Custom error: {type(exc).__name__}"

    model = AlwaysFailingModel(error_message="Model error", error_type=ValueError)

    retry = ModelRetryMiddleware(
        max_retries=1,
        initial_delay=0.01,
        jitter=False,
        on_failure=custom_formatter,
    )

    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
    assert "Custom error: ValueError" in ai_messages[-1].content

Domain

Subdomains

Frequently Asked Questions

What does test_model_retry_custom_failure_formatter() do?
test_model_retry_custom_failure_formatter() 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_custom_failure_formatter() defined?
test_model_retry_custom_failure_formatter() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_retry.py at line 229.

Analyze Your Own Codebase

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

Try Supermodel Free