Home / Function/ _format_output() — langchain Function Reference

_format_output() — langchain Function Reference

Architecture documentation for the _format_output() function in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4c39dba4_e991_3a3f_7dc3_2908930c9cf5["_format_output()"]
  80cebff4_efbd_4311_85e9_de0dc81a7eee["base.py"]
  4c39dba4_e991_3a3f_7dc3_2908930c9cf5 -->|defined in| 80cebff4_efbd_4311_85e9_de0dc81a7eee
  51b059af_20e0_9233_077d_cd590dd94dc8["run()"]
  51b059af_20e0_9233_077d_cd590dd94dc8 -->|calls| 4c39dba4_e991_3a3f_7dc3_2908930c9cf5
  c2f33b98_e5b2_c424_d7d3_8cbd05da78d1["arun()"]
  c2f33b98_e5b2_c424_d7d3_8cbd05da78d1 -->|calls| 4c39dba4_e991_3a3f_7dc3_2908930c9cf5
  8e2aa8da_dbf5_6b94_c484_cfc2e4ce5b93["_is_message_content_type()"]
  4c39dba4_e991_3a3f_7dc3_2908930c9cf5 -->|calls| 8e2aa8da_dbf5_6b94_c484_cfc2e4ce5b93
  755d2a8c_d4b5_192d_6c3f_0805ff5237f9["_stringify()"]
  4c39dba4_e991_3a3f_7dc3_2908930c9cf5 -->|calls| 755d2a8c_d4b5_192d_6c3f_0805ff5237f9
  style 4c39dba4_e991_3a3f_7dc3_2908930c9cf5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/tools/base.py lines 1250–1279

def _format_output(
    content: Any,
    artifact: Any,
    tool_call_id: str | None,
    name: str,
    status: str,
) -> ToolOutputMixin | Any:
    """Format tool output as a `ToolMessage` if appropriate.

    Args:
        content: The main content of the tool output.
        artifact: Any artifact data from the tool.
        tool_call_id: The ID of the tool call.
        name: The name of the tool.
        status: The execution status.

    Returns:
        The formatted output, either as a `ToolMessage` or the original content.
    """
    if isinstance(content, ToolOutputMixin) or tool_call_id is None:
        return content
    if not _is_message_content_type(content):
        content = _stringify(content)
    return ToolMessage(
        content,
        artifact=artifact,
        tool_call_id=tool_call_id,
        name=name,
        status=status,
    )

Subdomains

Called By

Frequently Asked Questions

What does _format_output() do?
_format_output() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/base.py.
Where is _format_output() defined?
_format_output() is defined in libs/core/langchain_core/tools/base.py at line 1250.
What does _format_output() call?
_format_output() calls 2 function(s): _is_message_content_type, _stringify.
What calls _format_output()?
_format_output() is called by 2 function(s): arun, run.

Analyze Your Own Codebase

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

Try Supermodel Free