{"record":{"id":"15fc495bc5f07aea","repo":"agentscope-ai/agentscope","slug":"invalid-input-item-r-expected-str-or-datablock","errorCode":null,"errorMessage":"Invalid input: {item!r}. Expected str or DataBlock.","messagePattern":"Invalid input: (.+?)\\. Expected str or DataBlock\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/embedding/_dashscope/_model.py","lineNumber":426,"sourceCode":"        \"\"\"Call the DashScope multimodal embedding API for a single batch.\n\n        Args:\n            inputs (`list[str | DataBlock]`):\n                ``str`` for text, ``DataBlock`` for images / videos.\n            **kwargs:\n                Forwarded to the API.\n\n        Returns:\n            `EmbeddingResponse`: Embedding vectors and usage info.\n        \"\"\"\n        formatted: list[dict[str, str]] = []\n        for item in inputs:\n            if isinstance(item, str):\n                formatted.append({\"text\": item})\n            elif isinstance(item, DataBlock):\n                formatted.append(self._format_data_block(item))\n            else:\n                raise ValueError(\n                    f\"Invalid input: {item!r}. Expected str or DataBlock.\",\n                )\n\n        api_kwargs: dict[str, Any] = {\n            \"input\": formatted,\n            \"model\": self.model,\n            \"api_key\": self.api_key,\n            **kwargs,\n        }\n\n        # Exclude api_key from cache identifier to avoid persisting secrets\n        # and to keep cache valid across key rotations.\n        cache_identifier = {\n            k: v for k, v in api_kwargs.items() if k != \"api_key\"\n        }\n\n        if self.embedding_cache:\n            cached = await self.embedding_cache.retrieve(","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/embedding/_dashscope/_model.py#L408-L444","documentation":"The DashScope multimodal embedding endpoint accepts only str and DataBlock items; _call_multimodal rejects any other element with a ValueError echoing the offending value.","triggerScenarios":"Calling the multimodal embedding model with list items that are neither str nor DataBlock — e.g. bytes, dicts, tuples, or raw file paths as strings-as-path objects.","commonSituations":"Feeding raw base64 strings or bytes instead of wrapping them in DataBlock with Base64Source; passing already-formatted API dicts; heterogeneous data from crawlers containing None.","solutions":["Wrap binary data in DataBlock(source=Base64Source(...)) and text in plain str","Coerce or drop non-conforming items before the call","Add a preprocessing step that maps your pipeline's types to str/DataBlock"],"exampleFix":"# before\nawait model([open(img, \"rb\").read()])\n# after\nfrom agentscope.message import DataBlock, Base64Source\nimport base64\nawait model([DataBlock(source=Base64Source(media_type=\"image/png\", data=base64.b64encode(raw).decode()))])","handlingStrategy":"type-guard","validationCode":"from agentscope.message import DataBlock\ndef ok(i): return isinstance(i, (str, DataBlock))\ninputs = [i for i in inputs if ok(i)]","typeGuard":"def is_multimodal_input(item) -> bool:\\n    from agentscope.message import DataBlock\\n    return isinstance(item, (str, DataBlock))","tryCatchPattern":"try:\\n    await model(items)\\nexcept ValueError as e:\\n    if \\\"Expected str or DataBlock\\\" in str(e): items = coerce(items); await model(items)\\n    else: raise","preventionTips":["Build DataBlock objects at ingestion","Centralize type coercion in one adapter layer"],"tags":["embedding","dashscope","multimodal","type-validation"],"backgroundTag":"invalid-input-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}