{"record":{"id":"27acd7a539552156","repo":"run-llama/llama_index","slug":"invalid-data-url-format-missing-comma-separator","errorCode":null,"errorMessage":"Invalid data URL format: missing comma separator","messagePattern":"Invalid data URL format: missing comma separator","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/utils.py","lineNumber":678,"sourceCode":"        return BytesIO(decoded_bytes)\n\n    elif path is not None:\n        path = Path(path) if isinstance(path, str) else path\n        data = path.read_bytes()\n        if as_base64:\n            return BytesIO(base64.b64encode(data))\n        return BytesIO(data)\n\n    elif url is not None:\n        parsed_url = urlparse(url)\n        if parsed_url.scheme == \"data\":\n            # Parse data URL: data:[<mediatype>][;base64],<data>\n            # The path contains everything after \"data:\"\n            data_part = parsed_url.path\n\n            # Split on the first comma to separate metadata from data\n            if \",\" not in data_part:\n                raise ValueError(\"Invalid data URL format: missing comma separator\")\n\n            metadata, url_data = data_part.split(\",\", 1)\n            is_base64_encoded = metadata.endswith(\";base64\")\n\n            if is_base64_encoded:\n                # Data is base64 encoded in the URL\n                decoded_data = base64.b64decode(url_data)\n                if as_base64:\n                    # Return as base64 bytes\n                    return BytesIO(base64.b64encode(decoded_data))\n                else:\n                    # Return decoded binary data\n                    return BytesIO(decoded_data)\n            else:\n                # Data is not base64 encoded in the URL (URL-encoded text)\n                if as_base64:\n                    # Encode the text data as base64\n                    return BytesIO(base64.b64encode(url_data.encode(\"utf-8\")))","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/utils.py#L660-L696","documentation":"Raised while resolving binary data from a `data:` URL when the URL has no comma separating the media-type metadata from the payload. RFC 2397 data URLs have the form `data:[<mediatype>][;base64],<data>`; the parser splits on the first comma, and if none exists the URL cannot contain any data. This is a fail-fast validation inside llama-index-core's binary resolution utility.","triggerScenarios":"Calling the binary resolver (e.g. `resolve_binary_data` / image readers that accept URLs) with a string like `\"data:text/plain\"`, `\"data:\"`, or a truncated data URL where the `,<payload>` part was cut off during copy-paste, templating, or string concatenation.","commonSituations":"Manually constructing data URLs instead of letting a library encode them; template strings that drop the payload when the base64 variable is empty; LLM/agent pipelines that pass model-generated or user-supplied URLs directly into image/document tools; URL truncation from max-length limits in logs or config files.","solutions":["Fix the URL so it contains a comma and payload: `data:<mediatype>[;base64],<data>`.","If building the URL yourself, use `f\"data:{mime};base64,{base64.b64encode(data).decode()}\"` so the comma is always present.","If the payload is genuinely empty, decide whether an empty payload is valid for your flow and handle it before calling the resolver.","Log the URL length/schema before passing it in to catch truncation early."],"exampleFix":"# before\nurl = \"data:image/png;base64\"  # missing comma + payload\nbuf = resolve_binary_data(url=url)\n\n# after\nimport base64\nurl = f\"data:image/png;base64,{base64.b64encode(png_bytes).decode()}\"\nbuf = resolve_binary_data(url=url)","handlingStrategy":"validation","validationCode":"def is_valid_data_url(url: str) -> bool:\n    if not url.startswith(\"data:\"):\n        return False\n    return \",\" in url[len(\"data:\"):]","typeGuard":null,"tryCatchPattern":"try:\n    buf = resolve_binary_data(url=url)\nexcept ValueError as e:\n    if \"data URL\" in str(e):\n        raise ValueError(f\"malformed data URL (len={len(url)}): regenerate it\") from e\n    raise","preventionTips":["Always build data URLs programmatically with base64.b64encode so the comma+payload are guaranteed.","Validate user/LLM-supplied URLs (scheme, comma presence, non-empty payload) before passing to resolvers.","Watch for truncation when data URLs pass through length-limited channels (env vars, logs, prompts)."],"tags":["data-url","validation","binary-data","python"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}