langchain-ai/langchain · error · ValueError

Block of type {block['type']} is not supported.

Error message

Block of type {block['type']} is not supported.

What it means

Raised when `convert_to_openai_data_block` (or a model path using it) receives a content block whose `type` is not one of the supported kinds (image, file, audio on the data-block path). It is a catch-all guard so unsupported block types fail loudly before a malformed request reaches OpenAI.

Source

Thrown at libs/core/langchain_core/messages/block_translators/openai.py:151

            error_msg = "Keys base64, url, or file_id required for file blocks."
            raise ValueError(error_msg)

    elif block["type"] == "audio":
        if "base64" in block or block.get("source_type") == "base64":
            # Handle v0 format: {"source_type": "base64", "data": "...", ...}
            # Handle v1 format: {"base64": "...", ...}
            base64_data = block["data"] if "source_type" in block else block["base64"]
            audio_format = block["mime_type"].split("/")[-1]
            formatted_block = {
                "type": "input_audio",
                "input_audio": {"data": base64_data, "format": audio_format},
            }
        else:
            error_msg = "Key base64 is required for audio blocks."
            raise ValueError(error_msg)
    else:
        error_msg = f"Block of type {block['type']} is not supported."
        raise ValueError(error_msg)

    return formatted_block


# v1 / Chat Completions
def _convert_to_v1_from_chat_completions(
    message: AIMessage,
) -> list[types.ContentBlock]:
    """Mutate a Chat Completions message to v1 format."""
    content_blocks: list[types.ContentBlock] = []
    if isinstance(message.content, str):
        if message.content:
            content_blocks = [{"type": "text", "text": message.content}]
        else:
            content_blocks = []

    for tool_call in message.tool_calls:
        content_blocks.append(

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Filter blocks before conversion: only pass `image`, `file`, and `audio` blocks to this converter
  2. Route `text` blocks to the string/text path and tool/reasoning blocks to their own handlers
  3. Check for typos in the `type` field of hand-built blocks

Example fix

# before
for block in message.content:
    openai_blocks.append(convert_to_openai_data_block(block))  # crashes on text blocks

# after
for block in message.content:
    if block.get("type") in {"image", "file", "audio"}:
        openai_blocks.append(convert_to_openai_data_block(block))
Defensive patterns

Strategy: type-guard

Validate before calling

SUPPORTED_DATA_BLOCKS = {"image", "file", "audio"}

def is_supported_data_block(block: dict) -> bool:
    return block.get("type") in SUPPORTED_DATA_BLOCKS

Type guard

def is_supported_data_block(block: dict) -> bool:
    return block.get("type") in {"image", "file", "audio"}

Prevention

When it happens

Trigger: Passing blocks like `{"type": "text", ...}`, `{"type": "reasoning", ...}`, `{"type": "tool_call", ...}` or a custom/typo'd type into the data-block converter; forwarding a full v1 content list where non-multimedia blocks were not filtered out first.

Common situations: Iterating over all content blocks of a message and sending each through the multimodal formatter without filtering; new block types added in newer langchain-core versions flowing into older conversion code; typos such as `"type": "imag"`.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/2f98b8eaf713a3d9. Report an issue: GitHub.