Home / Function/ _ensure_valid_tool_message_content() — langchain Function Reference

_ensure_valid_tool_message_content() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  b1594e89_965d_0f6c_e9b0_511a58b3e737["_ensure_valid_tool_message_content()"]
  2b046911_ea21_8e2e_ba0d_9d03da8d7bda["base.py"]
  b1594e89_965d_0f6c_e9b0_511a58b3e737 -->|defined in| 2b046911_ea21_8e2e_ba0d_9d03da8d7bda
  b988bc7d_ceff_06f1_193c_a22abc7a149f["_construct_responses_api_input()"]
  b988bc7d_ceff_06f1_193c_a22abc7a149f -->|calls| b1594e89_965d_0f6c_e9b0_511a58b3e737
  57d40c25_4875_99e8_1bae_5dd1aad3c2b3["_convert_chat_completions_blocks_to_responses()"]
  b1594e89_965d_0f6c_e9b0_511a58b3e737 -->|calls| 57d40c25_4875_99e8_1bae_5dd1aad3c2b3
  style b1594e89_965d_0f6c_e9b0_511a58b3e737 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/langchain_openai/chat_models/base.py lines 4005–4025

def _ensure_valid_tool_message_content(tool_output: Any) -> str | list[dict]:
    if isinstance(tool_output, str):
        return tool_output
    if isinstance(tool_output, list) and all(
        isinstance(block, dict)
        and block.get("type")
        in (
            "input_text",
            "input_image",
            "input_file",
            "text",
            "image_url",
            "file",
        )
        for block in tool_output
    ):
        return [
            _convert_chat_completions_blocks_to_responses(block)
            for block in tool_output
        ]
    return _stringify(tool_output)

Domain

Subdomains

Frequently Asked Questions

What does _ensure_valid_tool_message_content() do?
_ensure_valid_tool_message_content() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/base.py.
Where is _ensure_valid_tool_message_content() defined?
_ensure_valid_tool_message_content() is defined in libs/partners/openai/langchain_openai/chat_models/base.py at line 4005.
What does _ensure_valid_tool_message_content() call?
_ensure_valid_tool_message_content() calls 1 function(s): _convert_chat_completions_blocks_to_responses.
What calls _ensure_valid_tool_message_content()?
_ensure_valid_tool_message_content() is called by 1 function(s): _construct_responses_api_input.

Analyze Your Own Codebase

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

Try Supermodel Free