{"record":{"id":"1ff442932bb6e176","repo":"run-llama/llama_index","slug":"invalid-message-type-type-message-or-blocks","errorCode":null,"errorMessage":"Invalid message type: {type(message_or_blocks)}","messagePattern":"Invalid message type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/memory/memory.py","lineNumber":425,"sourceCode":"                for item in message_or_blocks\n            ):\n                blocks = []\n                for item in message_or_blocks:\n                    if not isinstance(item, CachePoint):\n                        blocks.append(\n                            cast(\n                                Union[\n                                    TextBlock,\n                                    ImageBlock,\n                                    AudioBlock,\n                                    VideoBlock,\n                                    DocumentBlock,\n                                ],\n                                item,\n                            )\n                        )\n            else:\n                raise ValueError(f\"Invalid message type: {type(message_or_blocks)}\")\n        elif isinstance(message_or_blocks, str):\n            blocks = [TextBlock(text=message_or_blocks)]\n        else:\n            raise ValueError(f\"Invalid message type: {type(message_or_blocks)}\")\n\n        # Estimate the token count for each block\n        for block in blocks:\n            if isinstance(block, TextBlock):\n                token_count += len(self.tokenizer_fn(block.text))\n            elif isinstance(block, ImageBlock):\n                token_count += self.image_token_size_estimate\n            elif isinstance(block, VideoBlock):\n                token_count += self.video_token_size_estimate\n            elif isinstance(block, AudioBlock):\n                token_count += self.audio_token_size_estimate\n            elif isinstance(block, DocumentBlock):\n                token_count += self.document_token_size_estimate\n","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/memory/memory.py#L407-L443","documentation":"Error \"Invalid message type: {type(message_or_blocks)}\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/memory/memory.py:425 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a ChatMessage or a list of memory blocks; other types are not accepted.","Convert the value to a ChatMessage before calling put/aput."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}