{"record":{"id":"5904b4328714b07d","repo":"agentscope-ai/agentscope","slug":"invalid-input-item-r-expected-str-or-datablock-5904b4","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/_gemini/_model.py","lineNumber":416,"sourceCode":"        \"\"\"\n        from google.genai import types\n\n        contents: list[types.Content] = []\n        for item in inputs:\n            if isinstance(item, str):\n                contents.append(\n                    types.Content(\n                        parts=[types.Part.from_text(text=item)],\n                    ),\n                )\n            elif isinstance(item, DataBlock):\n                contents.append(\n                    types.Content(\n                        parts=[self._data_block_to_part(item)],\n                    ),\n                )\n            else:\n                raise ValueError(\n                    f\"Invalid input: {item!r}. Expected str or DataBlock.\",\n                )\n\n        config = types.EmbedContentConfig(\n            output_dimensionality=self.dimensions,\n            **kwargs,\n        )\n\n        start_time = datetime.now()\n        response = self.client.models.embed_content(\n            model=self.model,\n            contents=contents,\n            config=config,\n        )\n        time = (datetime.now() - start_time).total_seconds()\n\n        embeddings = [item.values for item in response.embeddings]\n","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/embedding/_gemini/_model.py#L398-L434","documentation":"The Gemini multimodal embedding path only accepts two input shapes per item: plain str (text) or a DataBlock instance (image/audio/video). Anything else (dict, bytes, int, PIL image, None) fails validation before the request is built.","triggerScenarios":"Calling the multimodal embedding model with items like {\"type\": \"image_url\", ...} raw dicts, raw bytes, or PIL Image objects instead of DataBlock wrappers; routed through _call_api -> _call_multimodal.","commonSituations":"Porting code from OpenAI-style embedding APIs that take dicts; assuming bytes or PIL images are accepted; older examples passing tuples of (data, mime_type).","solutions":["Wrap binary/structured items in DataBlock with a proper source (Base64Source for inline data)","Convert PIL images to PNG bytes and wrap in DataBlock with Base64Source and media_type","Keep plain strings as-is for text parts of the batch"],"exampleFix":"# before\nemb = await model(inputs=[{\"type\": \"image\", \"data\": png_bytes}])\n\n# after\nfrom agentscope.message import DataBlock, Base64Source\nblock = DataBlock(source=Base64Source(data=png_bytes, media_type=\"image/png\"))\nemb = await model(inputs=[\"describe\", block])","handlingStrategy":"type-guard","validationCode":"from agentscope.message import DataBlock\nok = all(isinstance(x, (str, DataBlock)) for x in inputs)","typeGuard":"from agentscope.message import DataBlock\nfrom typing import Union\n\ndef is_valid_multimodal_input(inputs: list) -> bool:\n    return all(isinstance(x, (str, DataBlock)) for x in inputs)","tryCatchPattern":"try:\n    emb = await model(inputs=inputs)\nexcept ValueError as e:\n    if \"Expected str or DataBlock\" in str(e):\n        inputs = [x if isinstance(x, (str, DataBlock)) else to_data_block(x) for x in inputs]\n        emb = await model(inputs=inputs)\n    else:\n        raise","preventionTips":["Always wrap media in DataBlock with a proper source","Write a to_data_block(obj) adapter for your raw types","Reject dict-shaped OpenAI-style items before calling the model"],"tags":["embedding","gemini","multimodal","input-validation","datablock"],"backgroundTag":"invalid-input-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}