HKUDS/DeepTutor · error · GenerationProviderError
Malformed image data URI.
Error message
Malformed image data URI.
What it means
_materialize received a data: URI whose payload after the comma is empty (src.partition(',') yielded nothing), so base64 decoding is impossible. The header exists but the base64 image body is missing or truncated before the comma.
Source
Thrown at deeptutor/services/imagegen/adapters/chat_completions.py:103
sources.append(src)
# Fallback: some variants nest images in the content parts array.
content = message.get("content")
if isinstance(content, list):
for part in content:
if not isinstance(part, dict):
continue
src = (part.get("image_url") or {}).get("url") or part.get("url")
if isinstance(src, str) and src.startswith(("data:image", "http")):
sources.append(src)
if not sources:
raise GenerationProviderError("Image response had no image in the assistant message.")
return sources
async def _materialize(self, client: httpx.AsyncClient, src: str) -> tuple[bytes, str]:
if src.startswith("data:"):
header, _, encoded = src.partition(",")
if not encoded:
raise GenerationProviderError("Malformed image data URI.")
content_type = header[5:].split(";", 1)[0].strip() or "image/png"
return base64.b64decode(encoded), content_type
resp = await client.get(src)
raise_for_provider(resp, "Image download")
content_type = resp.headers.get("content-type") or "image/png"
if not content_type.startswith("image/"):
content_type = "image/png"
return resp.content, content_type
__all__ = ["ChatCompletionsImagegenAdapter"]
View on GitHub (pinned to 3e82f13042)
Solutions
- Retry the generation — transient truncation from the provider is the most common cause
- Log the offending src string length to confirm it's empty vs truncated
- If reproducible with one model/provider, report or switch providers/adapters
Defensive patterns
Strategy: validation
Validate before calling
def valid_data_uri(src: str) -> bool:
return src.startswith("data:") and len(src.partition(",")[2]) > 0 Try / catch
try:
img = await adapter._materialize(client, src)
except GenerationProviderError as exc:
if "Malformed image data URI" in str(exc):
continue # skip bad part, try next source Prevention
- Validate data URIs before decoding when handling raw provider payloads
- Treat empty-payload data URIs as transient and retry generation
When it happens
Trigger: A content part with url like "data:image/png;base64," (empty payload), or a malformed URI where the image bytes were dropped/truncated in transit or by the provider.
Common situations: Provider bug or truncation when inlining images; intermediary proxy stripping large bodies; model emitting a placeholder data URI.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- No endpoint URL configured for image generation.
- Image generation request error: {exc}
- Chat model returned no image. Check the model supports image
- Image response had no image in the assistant message.
- No endpoint URL configured for image generation.
AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27).
Data as JSON: /api/errors/b000c8557fe0dd3b.
Report an issue: GitHub.