Home / Function/ _format_failure_message() — langchain Function Reference

_format_failure_message() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  a235f099_6804_8d79_50f5_13bbaa648627["_format_failure_message()"]
  33f83a05_ad1b_0c1c_e484_ac91455db157["ToolRetryMiddleware"]
  a235f099_6804_8d79_50f5_13bbaa648627 -->|defined in| 33f83a05_ad1b_0c1c_e484_ac91455db157
  7a031c34_097e_d25a_0210_cf5d0d368b98["_handle_failure()"]
  7a031c34_097e_d25a_0210_cf5d0d368b98 -->|calls| a235f099_6804_8d79_50f5_13bbaa648627
  style a235f099_6804_8d79_50f5_13bbaa648627 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/tool_retry.py lines 237–254

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

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

        Returns:
            Formatted error message string.
        """
        exc_type = type(exc).__name__
        exc_msg = str(exc)
        attempt_word = "attempt" if attempts_made == 1 else "attempts"
        return (
            f"Tool '{tool_name}' failed after {attempts_made} {attempt_word} "
            f"with {exc_type}: {exc_msg}. Please try again."
        )

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/tool_retry.py.
Where is _format_failure_message() defined?
_format_failure_message() is defined in libs/langchain_v1/langchain/agents/middleware/tool_retry.py at line 237.
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