run-llama/llama_index · error · ValueError
Unsupported message content type: {type(bank_message.content
Error message
Unsupported message content type: {type(bank_message.content)} What it means
The message-level counterpart in rich.py: RichContext.format_messages() accepts bank messages whose content is either a plain string or a list of content blocks. Anything else (an int, a dict, a single block object instead of a list, custom objects) hits ValueError(f"Unsupported message content type: {type(bank_message.content)}"). The check is on the Python type of the content attribute, before per-block conversion even starts.
Source
Thrown at llama-index-core/llama_index/core/prompts/rich.py:127
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
- Make content a plain string for text-only messages: bank_message(role='user', content='hello').
- Or make content a list of typed block objects: content=[TextBlock(text='hello'), ImageBlock(url=...)] — never a single unwrapped block or a dict.
- If content comes from serialized data, parse dicts into the proper block classes before formatting.
- Normalize defensively: wrap non-list, non-str content (or None) into [TextBlock(text=str(content))] before passing it in, if losing structure is acceptable.
Example fix
# before
msg = bank_message(role="user", content={"text": "hi"}) # dict -> ValueError
msg2 = bank_message(role="user", content=TextBlock(text="hi")) # bare block -> ValueError
# after
msg = bank_message(role="user", content="hi") # str is fine
msg2 = bank_message(role="user", content=[TextBlock(text="hi")]) # list of blocks is fine Defensive patterns
Strategy: type-guard
Validate before calling
def assert_bank_message_content(msg) -> None:
c = msg.content
if not isinstance(c, (str, list)):
raise TypeError(
f"message content must be str or list of blocks, got {type(c).__name__}"
) Type guard
def has_formattable_content(msg) -> bool:
"""True when rich.py can convert this message (str or list content)."""
return isinstance(msg.content, str) or isinstance(msg.content, list) Prevention
- Always build bank messages with str or list-of-typed-blocks content.
- When loading messages from serialized data, reconstruct typed block objects instead of leaving dicts.
- Never pass a single bare block or dict as content — wrap in a list and use the proper block class.
When it happens
Trigger: Constructing a bank/message object with content=dict(...) or content=SomeBlock(...) (a single block, not a list), or content=None, then calling RichPromptTemplate.format(...) / rich_context.format_messages(...). Only str and list-of-blocks content pass the isinstance checks.
Common situations: Hand-building messages for Rich templates instead of using the provided helpers; dataclasses/pydantic v2 models whose attributes auto-coerce; content loaded from JSON where a block ended up as a raw dict instead of a typed block object.
Related errors
- Unsupported content block type: {bank_block.type}
- code_execute_fn must be provided for CodeActAgent
- LLM only supports text inputs
- The provided image string is not base64-encoded
- image_node.image is neither a string or None.
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/f811adcaf84a323f.
Report an issue: GitHub.