run-llama/llama_index · error · ValueError

Unsupported content block type: {bank_block.type}

Error message

Unsupported content block type: {bank_block.type}

What it means

In prompts/rich.py, when a RichContext converts message-bank messages to llama-index ChatMessages, each content block is mapped by its BanksContentBlockType. Only text, image_url, audio, video, and document are handled; any other enum value falls through to ValueError(f"Unsupported content block type: {bank_block.type}"). This is a coverage gap between the banks SDK's content-block enum and llama-index's converter, not a user-format error per se.

Source

Thrown at llama-index-core/llama_index/core/prompts/rich.py:119

                    ChatMessage(role=bank_message.role, content=bank_message.content)
                )
            elif isinstance(bank_message.content, list):
                llama_blocks: list[ContentBlock] = []
                for bank_block in bank_message.content:
                    if bank_block.type == BanksContentBlockType.text:
                        llama_blocks.append(TextBlock(text=bank_block.text))
                    elif bank_block.type == BanksContentBlockType.image_url:
                        llama_blocks.append(ImageBlock(url=bank_block.image_url.url))
                    elif bank_block.type == BanksContentBlockType.audio:
                        llama_blocks.append(AudioBlock(url=bank_block.input_audio.data))
                    elif bank_block.type == BanksContentBlockType.video:
                        llama_blocks.append(VideoBlock(url=bank_block.input_video.data))
                    elif bank_block.type == BanksContentBlockType.document:
                        llama_blocks.append(
                            DocumentBlock(url=bank_block.input_document.data)
                        )
                    else:
                        raise ValueError(
                            f"Unsupported content block type: {bank_block.type}"
                        )

                llama_messages.append(
                    ChatMessage(role=bank_message.role, content=llama_blocks)
                )
            else:
                raise ValueError(
                    f"Unsupported message content type: {type(bank_message.content)}"
                )

        if self.output_parser is not None:
            llama_messages = self.output_parser.format_messages(llama_messages)

        return llama_messages

    def get_template(self, llm: Optional[BaseLLM] = None) -> str:
        return self.template_str

View on GitHub (pinned to afd0fef371)

Solutions

  1. Pin compatible versions: upgrade llama-index-core to a release whose rich.py maps the block type you use, or downgrade the banks package to one whose enum only contains mapped types.
  2. Restrict your Rich template messages to supported blocks (text, image_url, audio, video, document).
  3. If you control the message list, strip/convert unsupported blocks to text before formatting.
  4. Longer term: subclass/extend the converter (or patch the mapping) to handle the extra block type, and upstream the change to llama-index.

Example fix

# before
msg = bank_message(
    role="user",
    content=[TextBlock(...), SomeNewBlockType(...)],  # not in rich.py mapping
)
llama_messages = rich_context.format_messages([msg])  # -> ValueError

# after
msg = bank_message(
    role="user",
    content=[TextBlock(...)],  # stick to mapped types (text/image/audio/video/doc)
)
llama_messages = rich_context.format_messages([msg])
Defensive patterns

Strategy: type-guard

Validate before calling

SUPPORTED_BLOCK_TYPES = {"text", "image_url", "audio", "video", "document"}

def assert_bank_blocks_supported(messages) -> None:
    for m in messages:
        if isinstance(m.content, list):
            for b in m.content:
                if getattr(b, "type", None) not in SUPPORTED_BLOCK_TYPES:
                    raise TypeError(
                        f"block type {getattr(b, 'type', None)!r} not mapped by rich.py; "
                        "upgrade llama-index-core or drop the block."
                    )

Type guard

def is_supported_bank_block(block) -> bool:
    t = getattr(block, "type", None)
    return isinstance(t, str) and t in {"text", "image_url", "audio", "video", "document"}

Prevention

When it happens

Trigger: Using a Rich prompt template whose messages include a content-block type the installed llama-index-core version does not map — e.g. a newer banks SDK adds a block type (file, tool_call, thinking, etc.) and you feed it through rich_utils / RichPromptTemplate.format(); the else-branch raises during conversion.

Common situations: Version skew: the `banks` (message-bank) package upgraded ahead of llama-index-core, or running a llama-index fork/nightly where the mapping lags. Also triggered by manually constructing bank messages with exotic block types and passing them to a RichContext.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/747166ab5197cb5b. Report an issue: GitHub.