{"record":{"id":"be6a5e72b93c673e","repo":"oobabooga/textgen","slug":"invalid-base64-image-data-e","errorCode":null,"errorMessage":"Invalid base64 image data: {e}","messagePattern":"Invalid base64 image data: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/image_utils.py","lineNumber":46,"sourceCode":"    buffered = io.BytesIO()\n    # Save image to an in-memory bytes buffer in PNG format\n    image.save(buffered, format=\"PNG\")\n    # Encode the bytes to a base64 string\n    return base64.b64encode(buffered.getvalue()).decode('utf-8')\n\n\ndef decode_base64_image(base64_string: str) -> Image.Image:\n    \"\"\"Decodes a base64 string to a PIL Image.\"\"\"\n    try:\n        if base64_string.startswith('data:image/'):\n            base64_string = base64_string.split(',', 1)[1]\n\n        image_data = base64.b64decode(base64_string)\n        image = Image.open(io.BytesIO(image_data))\n        return image\n    except Exception as e:\n        logger.error(f\"Failed to decode base64 image: {e}\")\n        raise ValueError(f\"Invalid base64 image data: {e}\")\n\n\ndef process_message_content(content: Any) -> Tuple[str, List[Image.Image]]:\n    \"\"\"\n    Processes message content that may contain text and images.\n    Returns: A tuple of (text_content, list_of_pil_images).\n    \"\"\"\n    if isinstance(content, str):\n        return content, []\n\n    if isinstance(content, list):\n        text_parts = []\n        images = []\n        for item in content:\n            if not isinstance(item, dict):\n                continue\n\n            item_type = item.get('type', '')","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/image_utils.py#L28-L64","documentation":"Error \"Invalid base64 image data: {e}\" thrown in oobabooga/textgen.","triggerScenarios":"Raised in modules/image_utils.py when decoding base64 image data supplied to the API (e.g. in a multimodal chat message image_url) fails. Triggers when the payload is not valid base64, has data-URI prefix issues, wrong padding, or contains non-image bytes.","commonSituations":"See trigger scenarios.","solutions":["Verify the image string is valid base64, including correct padding and no data-URI prefix unless expected.","Re-encode the image with base64.b64encode before sending it."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}