{"record":{"id":"2c557026eb040a23","repo":"agentscope-ai/agentscope","slug":"unsupported-image-source-type-type-source","errorCode":null,"errorMessage":"Unsupported image source type: {type(source)}","messagePattern":"Unsupported image source type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_dashscope_formatter.py","lineNumber":135,"sourceCode":"    ) -> dict[str, Any]:\n        \"\"\"Convert an image source to OpenAI-compatible ``image_url`` format.\n\n        Local ``file://`` URLs are read from disk and converted to base64\n        data URIs. Remote URLs are passed through unchanged.\n        \"\"\"\n        if isinstance(source, Base64Source):\n            url = f\"data:{source.media_type};base64,{source.data}\"\n        elif isinstance(source, URLSource):\n            url_str = str(source.url)\n            if url_str.startswith(\"file://\"):\n                local_path = url_str.removeprefix(\"file://\")\n                with open(local_path, \"rb\") as f:\n                    encoded = base64.b64encode(f.read()).decode(\"utf-8\")\n                url = f\"data:{source.media_type};base64,{encoded}\"\n            else:\n                url = url_str\n        else:\n            raise ValueError(f\"Unsupported image source type: {type(source)}\")\n\n        return {\n            \"type\": \"image_url\",\n            \"image_url\": {\"url\": url},\n        }\n\n    @staticmethod\n    def _format_video_source(\n        source: URLSource | Base64Source,\n    ) -> dict[str, Any]:\n        \"\"\"Convert a video source to DashScope's ``video_url`` format\n        (OpenAI-compatible extension).\n\n        Local ``file://`` URLs are read from disk and converted to base64\n        data URIs. Remote URLs are passed through unchanged.\n        \"\"\"\n        if isinstance(source, Base64Source):\n            url = f\"data:{source.media_type};base64,{source.data}\"","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_dashscope_formatter.py#L117-L153","documentation":"The DashScope (Qwen) formatter builds an OpenAI-style image_url payload and only handles supported image source types (inline base64/local file -> data URL, and URL sources). Any other source object (None, dict, custom class) raises this ValueError before the request is sent.","triggerScenarios":"Passing a message with an image DataBlock whose source is an unrecognized type; _format_dashscope_data_block -> _format_image_source falls to the final else.","commonSituations":"Version mismatch producing isinstance failures; building image blocks with raw dicts from JSON payloads; empty DataBlock with source=None from failed downloads.","solutions":["Ensure one agentscope version is installed and DataBlock sources come from agentscope.message","Convert images to URLSource or Base64Source before adding to the message","Validate blocks before sending (see type guard below)"],"exampleFix":"# before\nblock = DataBlock(source=None, media_type=\"image/png\")\n\n# after\nfrom agentscope.message import DataBlock, URLSource\nblock = DataBlock(source=URLSource(url=img_url, media_type=\"image/png\"))","handlingStrategy":"type-guard","validationCode":"from agentscope.message import Base64Source, URLSource\nfor block in msg_image_blocks:\n    if not isinstance(getattr(block, \"source\", None), (Base64Source, URLSource)):\n        raise TypeError(\"image block source unsupported\")","typeGuard":"from agentscope.message import DataBlock, Base64Source, URLSource\n\ndef image_block_ok(block: DataBlock) -> bool:\n    return isinstance(getattr(block, \"source\", None), (Base64Source, URLSource))","tryCatchPattern":"try:\n    resp = await model(msg)\nexcept ValueError as e:\n    if \"Unsupported image source type\" in str(e):\n        msg = normalize_image_blocks(msg)\n        resp = await model(msg)\n    else:\n        raise","preventionTips":["Convert images to URL or base64 sources at ingestion time","Never leave DataBlock.source as None after a failed download","Validate message content in tests with the type guard"],"tags":["dashscope","qwen","formatter","image","source-type"],"backgroundTag":"unsupported-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}