Home / Function/ _format_message_content() — langchain Function Reference

_format_message_content() — langchain Function Reference

Architecture documentation for the _format_message_content() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  933ce559_e66a_509b_6b21_a22c244fe2e4["_format_message_content()"]
  9591e0fc_6d18_28d3_cea9_e4a5cf7f2b59["chat_models.py"]
  933ce559_e66a_509b_6b21_a22c244fe2e4 -->|defined in| 9591e0fc_6d18_28d3_cea9_e4a5cf7f2b59
  e58980fb_2231_9ea9_a3a2_b6d2a0c2c02d["_convert_message_to_dict()"]
  e58980fb_2231_9ea9_a3a2_b6d2a0c2c02d -->|calls| 933ce559_e66a_509b_6b21_a22c244fe2e4
  style 933ce559_e66a_509b_6b21_a22c244fe2e4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/groq/langchain_groq/chat_models.py lines 1270–1290

def _format_message_content(content: Any) -> Any:
    """Format message content for Groq API.

    Converts LangChain image content blocks to Groq's expected image_url format.

    Args:
        content: The message content (string or list of content blocks).

    Returns:
        Formatted content suitable for Groq API.
    """
    if content and isinstance(content, list):
        formatted: list = []
        for block in content:
            # Handle LangChain standard data content blocks (image, audio, file)
            if isinstance(block, dict) and is_data_content_block(block):
                formatted.append(convert_to_openai_data_block(block))
            else:
                formatted.append(block)
        return formatted
    return content

Domain

Subdomains

Frequently Asked Questions

What does _format_message_content() do?
_format_message_content() is a function in the langchain codebase, defined in libs/partners/groq/langchain_groq/chat_models.py.
Where is _format_message_content() defined?
_format_message_content() is defined in libs/partners/groq/langchain_groq/chat_models.py at line 1270.
What calls _format_message_content()?
_format_message_content() is called by 1 function(s): _convert_message_to_dict.

Analyze Your Own Codebase

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

Try Supermodel Free