{"record":{"id":"71fecd5668fe4c81","repo":"langchain-ai/langchain","slug":"image-url-not-a-data-uri-appending-as-non-standar","errorCode":null,"errorMessage":"Image URL not a data URI; appending as non-standard block.","messagePattern":"Image URL not a data URI; appending as non-standard block\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/messages/block_translators/google_genai.py","lineNumber":425,"sourceCode":"                                if mime_type:\n                                    image_url_b64_block[\"mime_type\"] = mime_type\n\n                            converted_blocks.append(\n                                cast(\"types.ImageContentBlock\", image_url_b64_block)\n                            )\n                        except Exception:\n                            # Not valid base64, treat as non-standard\n                            converted_blocks.append(\n                                {\n                                    \"type\": \"non_standard\",\n                                    \"value\": item,\n                                }\n                            )\n                else:\n                    # This likely won't be reached according to previous implementations\n                    converted_blocks.append({\"type\": \"non_standard\", \"value\": item})\n                    msg = \"Image URL not a data URI; appending as non-standard block.\"\n                    raise ValueError(msg)\n            elif item_type == \"function_call\":\n                # Handle Google GenAI function calls\n                function_call_block: types.ToolCall = {\n                    \"type\": \"tool_call\",\n                    \"name\": item.get(\"name\", \"\"),\n                    \"args\": item.get(\"args\", {}),\n                    \"id\": item.get(\"id\", \"\"),\n                }\n                converted_blocks.append(function_call_block)\n            elif item_type == \"file_data\":\n                # Handle FileData URI-based content\n                file_block: types.FileContentBlock = {\n                    \"type\": \"file\",\n                    \"url\": item.get(\"file_uri\", \"\"),\n                }\n                if mime_type := item.get(\"mime_type\"):\n                    file_block[\"mime_type\"] = mime_type\n                converted_blocks.append(file_block)","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/messages/block_translators/google_genai.py#L407-L443","documentation":"Raised by the Google GenAI content block translator when an image item carries a URL that is not a `data:` URI. The translator can only inline images for Gemini as base64 data URIs; a remote http(s) URL cannot be passed through this path, so the block is recorded as non-standard and a ValueError is raised.","triggerScenarios":"Sending an AIMessage/content block to the google-genai path whose image entry is `{\"type\": \"image_url\", \"image_url\": {\"url\": \"https://...\"}}` or a plain dict with an `https://` URL, where the URL is not a `data:image/...;base64,...` URI and no file_data/mime_type alternative matched.","commonSituations":"Copying OpenAI-style image URL blocks into Gemini calls; hotlinking a CDN image instead of uploading via the Gemini Files API; assuming Gemini fetches remote image URLs like the OpenAI image_url parameter does.","solutions":["Download the image and pass it as a data URI: `f\"data:{mime};base64,{b64data}\"`","Or upload the file to the Gemini Files API and pass a `file_data` block with the resulting file URI","If you control the block dict, set `mime_type` alongside the base64 data so the base64 branch is taken instead"],"exampleFix":"# before\nblock = {\"type\": \"image_url\", \"image_url\": {\"url\": \"https://example.com/cat.png\"}}\n\n# after\nimport base64, mimetypes\nraw = open(\"cat.png\", \"rb\").read()\nb64 = base64.b64encode(raw).decode()\nblock = {\"type\": \"image_url\", \"image_url\": {\"url\": f\"data:{mimetypes.guess_type('cat.png')[0]};base64,{b64}\"}}","handlingStrategy":"validation","validationCode":"def is_gemini_safe_image(block: dict) -> bool:\n    url = block.get(\"url\") or block.get(\"image_url\", {}).get(\"url\", \"\")\n    return url.startswith(\"data:\")","typeGuard":"def is_data_uri_image(block: dict) -> bool:\n    url = block.get(\"url\") or block.get(\"image_url\", {}).get(\"url\", \"\")\n    return isinstance(url, str) and url.startswith(\"data:\")","tryCatchPattern":"try:\n    resp = gemini_model.invoke([msg])\nexcept ValueError as e:\n    if \"Image URL not a data URI\" in str(e):\n        msg = inline_image_as_data_uri(msg)  # download + base64 encode, then retry\n    else:\n        raise","preventionTips":["Always inline images for Gemini as data: URIs or upload via the Files API","Never assume Gemini fetches remote https image URLs","Centralize a to_gemini_blocks() normalization step before model invocation"],"tags":["gemini","google-genai","image","content-blocks","data-uri"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}