run-llama/llama_index · error · ValueError

Invalid message type: {type(message_or_blocks)}

Error message

Invalid message type: {type(message_or_blocks)}

What it means

Error "Invalid message type: {type(message_or_blocks)}" thrown in run-llama/llama_index.

Source

Thrown at llama-index-core/llama_index/core/memory/memory.py:425

                for item in message_or_blocks
            ):
                blocks = []
                for item in message_or_blocks:
                    if not isinstance(item, CachePoint):
                        blocks.append(
                            cast(
                                Union[
                                    TextBlock,
                                    ImageBlock,
                                    AudioBlock,
                                    VideoBlock,
                                    DocumentBlock,
                                ],
                                item,
                            )
                        )
            else:
                raise ValueError(f"Invalid message type: {type(message_or_blocks)}")
        elif isinstance(message_or_blocks, str):
            blocks = [TextBlock(text=message_or_blocks)]
        else:
            raise ValueError(f"Invalid message type: {type(message_or_blocks)}")

        # Estimate the token count for each block
        for block in blocks:
            if isinstance(block, TextBlock):
                token_count += len(self.tokenizer_fn(block.text))
            elif isinstance(block, ImageBlock):
                token_count += self.image_token_size_estimate
            elif isinstance(block, VideoBlock):
                token_count += self.video_token_size_estimate
            elif isinstance(block, AudioBlock):
                token_count += self.audio_token_size_estimate
            elif isinstance(block, DocumentBlock):
                token_count += self.document_token_size_estimate

View on GitHub (pinned to afd0fef371)

Solutions

  1. Pass a ChatMessage or a list of memory blocks; other types are not accepted.
  2. Convert the value to a ChatMessage before calling put/aput.

When it happens

Trigger: Thrown at llama-index-core/llama_index/core/memory/memory.py:425 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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