langchain-ai/langchain · error · ValueError
Image URL not a data URI; appending as non-standard block.
Error message
Image URL not a data URI; appending as non-standard block.
What it means
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.
Source
Thrown at libs/core/langchain_core/messages/block_translators/google_genai.py:425
if mime_type:
image_url_b64_block["mime_type"] = mime_type
converted_blocks.append(
cast("types.ImageContentBlock", image_url_b64_block)
)
except Exception:
# Not valid base64, treat as non-standard
converted_blocks.append(
{
"type": "non_standard",
"value": item,
}
)
else:
# This likely won't be reached according to previous implementations
converted_blocks.append({"type": "non_standard", "value": item})
msg = "Image URL not a data URI; appending as non-standard block."
raise ValueError(msg)
elif item_type == "function_call":
# Handle Google GenAI function calls
function_call_block: types.ToolCall = {
"type": "tool_call",
"name": item.get("name", ""),
"args": item.get("args", {}),
"id": item.get("id", ""),
}
converted_blocks.append(function_call_block)
elif item_type == "file_data":
# Handle FileData URI-based content
file_block: types.FileContentBlock = {
"type": "file",
"url": item.get("file_uri", ""),
}
if mime_type := item.get("mime_type"):
file_block["mime_type"] = mime_type
converted_blocks.append(file_block)View on GitHub (pinned to e32fa9a52e)
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
Example fix
# before
block = {"type": "image_url", "image_url": {"url": "https://example.com/cat.png"}}
# after
import base64, mimetypes
raw = open("cat.png", "rb").read()
b64 = base64.b64encode(raw).decode()
block = {"type": "image_url", "image_url": {"url": f"data:{mimetypes.guess_type('cat.png')[0]};base64,{b64}"}} Defensive patterns
Strategy: validation
Validate before calling
def is_gemini_safe_image(block: dict) -> bool:
url = block.get("url") or block.get("image_url", {}).get("url", "")
return url.startswith("data:") Type guard
def is_data_uri_image(block: dict) -> bool:
url = block.get("url") or block.get("image_url", {}).get("url", "")
return isinstance(url, str) and url.startswith("data:") Try / catch
try:
resp = gemini_model.invoke([msg])
except ValueError as e:
if "Image URL not a data URI" in str(e):
msg = inline_image_as_data_uri(msg) # download + base64 encode, then retry
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- mime_type key is required for base64 data.
- Unsupported source type. Only 'url' and 'base64' are support
- Must provide one of: url, base64, or file_id
- Keys base64, url, or file_id required for file blocks.
- Key base64 is required for audio blocks.
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/71fecd5668fe4c81.
Report an issue: GitHub.