{"record":{"id":"4d8eb8619cc393b5","repo":"run-llama/llama_index","slug":"the-provided-image-string-is-not-base64-encoded","errorCode":null,"errorMessage":"The provided image string is not base64-encoded","messagePattern":"The provided image string is not base64-encoded","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/base/llms/generic_utils.py","lineNumber":350,"sourceCode":"def image_node_to_image_block(image_node: ImageNode) -> ImageBlock:\n    \"\"\"\n    Get an ImageBlock from an ImageNode.\n\n    Args:\n        image_node (ImageNode): ImageNode to convert.\n\n    Returns:\n        ImageBlock: block representation of the node.\n\n    Raises:\n        ValueError: when the image provided within the ImageNode is not correctly base64-encoded.\n\n    \"\"\"\n    if isinstance(image_node.image, str):\n        try:\n            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":332,"sourceCodeEnd":367,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/base/llms/generic_utils.py#L332-L367","documentation":"Raised by image_node_to_image_block when ImageNode.image is a string that fails strict base64 decoding (base64.b64decode with validate=True raising BinasciiError). The string must be valid base64-encoded image bytes, not a path or URL.","triggerScenarios":"Building an ImageBlock from an ImageNode whose .image was set to a file path, a URL, or malformed/padded base64; truncated base64 from a DB or JSON round-trip.","commonSituations":"Setting ImageNode(image=\"/tmp/photo.png\") intending a path; whitespace or data:image/png;base64, prefixes embedded in the string; copy-paste truncation of base64 payloads.","solutions":["If the string is a path, set image_path=... (or metadata['file_path']) and leave image=None instead.","If it's a URL, set image_url=... instead of image=.","If it is meant to be raw base64, strip prefixes/whitespace and re-encode the source bytes correctly (base64.b64encode(open(p,'rb').read()).decode())."],"exampleFix":"# before\nnode = ImageNode(image=\"/data/cat.png\")\nblock = image_node_to_image_block(node)\n\n# after\nnode = ImageNode(image_path=\"/data/cat.png\")\nblock = image_node_to_image_block(node)","handlingStrategy":"validation","validationCode":"import base64, binascii\ntry:\n    base64.b64decode(s, validate=True)\n    is_b64 = True\nexcept (binascii.Error, ValueError):\n    is_b64 = False\nnode = ImageNode(image=s) if is_b64 else ImageNode(image_path=s)","typeGuard":"def looks_like_base64(s: str) -> bool:\n    import base64, binascii\n    try:\n        base64.b64decode(s, validate=True)\n        return True\n    except (binascii.Error, ValueError):\n        return False","tryCatchPattern":null,"preventionTips":["Use image_path/image_url fields for paths and URLs; reserve image= for base64.","Strip data:...;base64, prefixes and whitespace before storing base64."],"tags":["llama-index","image","base64","multimodal"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}