Home / Function/ is_data_content_block() — langchain Function Reference

is_data_content_block() — langchain Function Reference

Architecture documentation for the is_data_content_block() function in content.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  64c47965_895a_2cc2_b405_fe97d81684af["is_data_content_block()"]
  c7f11daf_e104_efbe_7225_f1d6da8e8630["content.py"]
  64c47965_895a_2cc2_b405_fe97d81684af -->|defined in| c7f11daf_e104_efbe_7225_f1d6da8e8630
  c790e000_5917_c7c6_0720_37dcb51f1c97["_get_data_content_block_types()"]
  64c47965_895a_2cc2_b405_fe97d81684af -->|calls| c790e000_5917_c7c6_0720_37dcb51f1c97
  style 64c47965_895a_2cc2_b405_fe97d81684af fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/content.py lines 908–947

def is_data_content_block(block: dict) -> bool:
    """Check if the provided content block is a data content block.

    Returns True for both v0 (old-style) and v1 (new-style) multimodal data blocks.

    Args:
        block: The content block to check.

    Returns:
        `True` if the content block is a data content block, `False` otherwise.
    """
    if block.get("type") not in _get_data_content_block_types():
        return False

    if any(key in block for key in ("url", "base64", "file_id", "text")):
        # Type is valid and at least one data field is present
        # (Accepts old-style image and audio URLContentBlock)

        # 'text' is checked to support v0 PlainTextContentBlock types
        # We must guard against new style TextContentBlock which also has 'text' `type`
        # by ensuring the presence of `source_type`
        if block["type"] == "text" and "source_type" not in block:  # noqa: SIM103  # This is more readable
            return False

        return True

    if "source_type" in block:
        # Old-style content blocks had possible types of 'image', 'audio', and 'file'
        # which is not captured in the prior check
        source_type = block["source_type"]
        if (source_type == "url" and "url" in block) or (
            source_type == "base64" and "data" in block
        ):
            return True
        if (source_type == "id" and "id" in block) or (
            source_type == "text" and "url" in block
        ):
            return True

    return False

Domain

Subdomains

Frequently Asked Questions

What does is_data_content_block() do?
is_data_content_block() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/content.py.
Where is is_data_content_block() defined?
is_data_content_block() is defined in libs/core/langchain_core/messages/content.py at line 908.
What does is_data_content_block() call?
is_data_content_block() calls 1 function(s): _get_data_content_block_types.

Analyze Your Own Codebase

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

Try Supermodel Free