{"record":{"id":"1b01bdc5f061ab49","repo":"agentscope-ai/agentscope","slug":"text-embedding-model-self-model-r-only-accepts-s-1b01bd","errorCode":null,"errorMessage":"Text embedding model {self.model!r} only accepts str inputs, got {type(item).__name__}.","messagePattern":"Text embedding model (.+?) only accepts str inputs, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/embedding/_gemini/_model.py","lineNumber":324,"sourceCode":"        Passes the list of strings directly to ``embed_content``,\n        which returns one embedding per string.\n\n        Args:\n            inputs (`list[str | DataBlock]`):\n                Must all be ``str``; raises ``ValueError`` otherwise.\n            **kwargs:\n                Merged into ``EmbedContentConfig`` (e.g.\n                ``task_type``).\n\n        Returns:\n            `EmbeddingResponse`: Embedding vectors and usage info.\n        \"\"\"\n        from google.genai import types\n\n        texts: list[str] = []\n        for item in inputs:\n            if not isinstance(item, str):\n                raise ValueError(\n                    f\"Text embedding model {self.model!r} only accepts \"\n                    f\"str inputs, got {type(item).__name__}.\",\n                )\n            texts.append(item)\n\n        config = types.EmbedContentConfig(\n            output_dimensionality=self.dimensions,\n            **kwargs,\n        )\n\n        cache_key = {\n            \"model\": self.model,\n            \"contents\": texts,\n            \"output_dimensionality\": self.dimensions,\n            **kwargs,\n        }\n\n        if self.embedding_cache:","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/embedding/_gemini/_model.py#L306-L342","documentation":"The Gemini text embedding model wrapper validates that every element of the input list is a Python str before building the API request. Passing any non-str item (int, dict, DataBlock, None) raises ValueError immediately, client-side, before any network call.","triggerScenarios":"Calling the model with inputs like [\"hello\", 123], [None], or a list of DataBlock objects when the model was configured as a text-only embedding model (e.g. text-embedding-004 / gemini-embedding-001 in text mode) via _call_api -> _call_text.","commonSituations":"Feeding unnormalized pipeline data (numbers, None from empty strings, parsed JSON) straight into embed(); mixing multimodal DataBlocks into a text-only model configuration; version upgrades where inputs previously coerced to str now fail fast.","solutions":["Coerce all inputs to str before calling: [str(x) if x is not None else \"\" for x in inputs]","Filter or skip None/empty entries before embedding","If you meant to embed images/audio, use a multimodal-capable model config so _call_multimodal is used instead of _call_text"],"exampleFix":"# before\nembs = await model(inputs=[\"a\", 42, None])\n\n# after\ninputs = [str(x) for x in [\"a\", 42, None] if x is not None]\nembs = await model(inputs=inputs)","handlingStrategy":"type-guard","validationCode":"inputs = [x for x in inputs if isinstance(x, str) and x]\n# or coerce: inputs = [str(x) for x in inputs]","typeGuard":"def all_str(inputs: list) -> bool:\n    return all(isinstance(x, str) for x in inputs)","tryCatchPattern":"try:\n    embs = await model(inputs=inputs)\nexcept ValueError as e:\n    if \"only accepts str inputs\" in str(e):\n        inputs = [str(x) for x in inputs if x is not None]\n        embs = await model(inputs=inputs)\n    else:\n        raise","preventionTips":["Normalize pipeline data to str before embedding","Filter None/empty items early","Use a multimodal model config when non-text inputs are expected"],"tags":["embedding","gemini","type-validation","input-validation"],"backgroundTag":"invalid-input-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}