Home / Function/ _format_failure_message() — langchain Function Reference

_format_failure_message() — langchain Function Reference

Architecture documentation for the _format_failure_message() function in model_retry.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  edb7ba16_b462_070e_af1f_46c3f718cc0a["_format_failure_message()"]
  5e783bd0_a142_0fd6_3238_fc2d9985440d["ModelRetryMiddleware"]
  edb7ba16_b462_070e_af1f_46c3f718cc0a -->|defined in| 5e783bd0_a142_0fd6_3238_fc2d9985440d
  5f0811d1_ab8b_7642_81d3_ed55469793d6["_handle_failure()"]
  5f0811d1_ab8b_7642_81d3_ed55469793d6 -->|calls| edb7ba16_b462_070e_af1f_46c3f718cc0a
  style edb7ba16_b462_070e_af1f_46c3f718cc0a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/model_retry.py lines 172–188

    def _format_failure_message(exc: Exception, attempts_made: int) -> AIMessage:
        """Format the failure message when retries are exhausted.

        Args:
            exc: The exception that caused the failure.
            attempts_made: Number of attempts actually made.

        Returns:
            `AIMessage` with formatted error message.
        """
        exc_type = type(exc).__name__
        exc_msg = str(exc)
        attempt_word = "attempt" if attempts_made == 1 else "attempts"
        content = (
            f"Model call failed after {attempts_made} {attempt_word} with {exc_type}: {exc_msg}"
        )
        return AIMessage(content=content)

Domain

Subdomains

Called By

Frequently Asked Questions

What does _format_failure_message() do?
_format_failure_message() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/model_retry.py.
Where is _format_failure_message() defined?
_format_failure_message() is defined in libs/langchain_v1/langchain/agents/middleware/model_retry.py at line 172.
What calls _format_failure_message()?
_format_failure_message() is called by 1 function(s): _handle_failure.

Analyze Your Own Codebase

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

Try Supermodel Free