Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add better error handling for malformed data URIs
Co-authored-by: TomeHirata <[email protected]>
  • Loading branch information
Copilot and TomeHirata committed Oct 29, 2025
commit 71bd42a8bd34db9c5674bc4a2565f3f333c5f409
10 changes: 9 additions & 1 deletion dspy/clients/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,14 @@ def _convert_content_item_to_responses_format(item: dict[str, Any]) -> dict[str,
if len(parts) == 2:
header, data = parts
# Extract media type from header (e.g., "data:image/png;base64" -> "image/png")
media_type = header.split(";")[0].replace("data:", "")
# Handle both "data:image/png;base64" and "data:image/png" formats
media_type_parts = header.split(";")[0].replace("data:", "")
if media_type_parts:
media_type = media_type_parts
else:
# Fallback to a default media type if extraction fails
media_type = "image/png"

return {
"type": "input_image",
"source": {
Expand All @@ -515,6 +522,7 @@ def _convert_content_item_to_responses_format(item: dict[str, Any]) -> dict[str,
"data": data,
}
}
# If data URI is malformed (doesn't have comma separator), fall through to URL handling

# Otherwise treat as URL
return {
Expand Down