{"record":{"id":"c2ed0a4b44646f9a","repo":"FoundationAgents/OpenManus","slug":"unsupported-image-format-image","errorCode":null,"errorMessage":"Unsupported image format: {image}","messagePattern":"Unsupported image format: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"app/llm.py","lineNumber":556,"sourceCode":"                [{\"type\": \"text\", \"text\": content}]\n                if isinstance(content, str)\n                else content\n                if isinstance(content, list)\n                else []\n            )\n\n            # Add images to content\n            for image in images:\n                if isinstance(image, str):\n                    multimodal_content.append(\n                        {\"type\": \"image_url\", \"image_url\": {\"url\": image}}\n                    )\n                elif isinstance(image, dict) and \"url\" in image:\n                    multimodal_content.append({\"type\": \"image_url\", \"image_url\": image})\n                elif isinstance(image, dict) and \"image_url\" in image:\n                    multimodal_content.append(image)\n                else:\n                    raise ValueError(f\"Unsupported image format: {image}\")\n\n            # Update the message with multimodal content\n            last_message[\"content\"] = multimodal_content\n\n            # Add system messages if provided\n            if system_msgs:\n                all_messages = (\n                    self.format_messages(system_msgs, supports_images=True)\n                    + formatted_messages\n                )\n            else:\n                all_messages = formatted_messages\n\n            # Calculate tokens and check limits\n            input_tokens = self.count_message_tokens(all_messages)\n            if not self.check_token_limit(input_tokens):\n                raise TokenLimitExceeded(self.get_limit_error_message(input_tokens))\n","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/llm.py#L538-L574","documentation":"Raised by LLM.ask_with_images() when an element of the images argument is neither a string (treated as a URL or data-URI), nor a dict with a \"url\" key, nor a dict with an \"image_url\" key. Any other type — bytes, PIL objects, numpy arrays, file paths to local files without a data: scheme — is rejected because it cannot be mapped to the OpenAI image_url content-part shape.","triggerScenarios":"Passing images=[open(\"x.png\",\"rb\").read()] (bytes), images=[PIL.Image.open(...)], images=[{\"src\": \"data:image/png;base64,...\"}] (wrong key name), or a plain local path string that is fine syntactically but will fail at the API — only the three accepted shapes pass the guard.","commonSituations":"Loading images as bytes or PIL objects and assuming the client encodes them; using \"src\" or \"data\" keys instead of \"url\"; forgetting to base64-encode local files into a data URI string.","solutions":["Convert local images to a data URI string: \"data:image/png;base64,\" + base64.b64encode(open(p,\"rb\").read()).decode()","Pass dicts in the exact shapes: {\"url\": \"...\"} or {\"image_url\": {\"url\": \"...\"}}","For hosted images, pass the public https URL string directly"],"exampleFix":"# before\nimages = [open(\"chart.png\", \"rb\").read()]  # bytes -> ValueError\n\n# after\nimport base64\nimages = [\"data:image/png;base64,\" + base64.b64encode(open(\"chart.png\", \"rb\").read()).decode()]","handlingStrategy":"type-guard","validationCode":"def is_valid_image(image: object) -> bool:\n    if isinstance(image, str):\n        return True\n    if isinstance(image, dict):\n        return \"url\" in image or \"image_url\" in image\n    return False","typeGuard":"from typing import TypeGuard, Any\n\ndef is_supported_image(image: Any) -> TypeGuard[str | dict]:\n    return (\n        isinstance(image, str)\n        or (isinstance(image, dict) and (\"url\" in image or \"image_url\" in image))\n    )","tryCatchPattern":null,"preventionTips":["Encode local files to data URIs yourself; never pass raw bytes or PIL objects","Use exactly the shapes str | {'url': ...} | {'image_url': ...}","Validate the images list in one place (a helper) so all call sites share the guard"],"tags":["llm","images","multimodal","validation"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}