{"record":{"id":"8bf8b54ade26e05b","repo":"run-llama/llama_index","slug":"image-node-image-is-neither-a-string-or-none","errorCode":null,"errorMessage":"image_node.image is neither a string or None.","messagePattern":"image_node\\.image is neither a string or None\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/base/llms/generic_utils.py","lineNumber":366,"sourceCode":"            return ImageBlock(image=base64.b64decode(image_node.image, validate=True))\n        except BinasciiError:\n            raise ValueError(\"The provided image string is not base64-encoded\")\n    elif image_node.image is None:\n        if image_node.image_path is not None:\n            image_path: Optional[Path] = Path(image_node.image_path)\n        elif \"file_path\" in image_node.metadata:\n            image_path = image_node.metadata[\"file_path\"]\n        else:\n            image_path = image_node.image_path\n        return ImageBlock(\n            image=image_node.image,\n            url=image_node.image_url,\n            image_mimetype=image_node.image_mimetype,\n            path=image_path,\n        )\n\n    else:\n        raise ValueError(\"image_node.image is neither a string or None.\")\n","sourceCodeStart":348,"sourceCodeEnd":367,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/base/llms/generic_utils.py#L348-L367","documentation":"Raised by image_node_to_image_block when ImageNode.image is neither a str nor None (e.g. bytes, dict, or PIL object). The function only understands base64-string or absent image data; other binary representations are rejected.","triggerScenarios":"Setting ImageNode(image=open('x.png','rb').read()) (raw bytes), image=PIL.Image, or image=bytearray and then calling image_node_to_image_block.","commonSituations":"Reading files as bytes and assigning directly to .image; interop code that stores decoded bytes from another pipeline; assuming bytes are accepted because the field is loosely typed.","solutions":["If you have raw bytes, base64-encode them: image=base64.b64encode(raw).decode('utf-8').","If the data lives on disk or remotely, use image_path= or image_url= and keep image=None.","Add a construction-time check that image is None or a valid base64 str before creating ImageNodes."],"exampleFix":"# before\nnode = ImageNode(image=open('cat.png','rb').read())\n\n# after\nimport base64\nnode = ImageNode(image=base64.b64encode(open('cat.png','rb').read()).decode())\n# or simpler: node = ImageNode(image_path='cat.png')","handlingStrategy":"type-guard","validationCode":"assert image_node.image is None or isinstance(image_node.image, str), \"image must be base64 str or None\"","typeGuard":"def is_valid_image_value(v: Any) -> bool:\n    return v is None or isinstance(v, str)","tryCatchPattern":null,"preventionTips":["Encode raw bytes to base64 str before assigning to ImageNode.image.","Prefer image_path/image_url for file and remote sources."],"tags":["llama-index","image","type-validation","multimodal"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}