agentscope-ai/agentscope · error · ValueError
Text embedding model {self.model!r} only accepts str inputs,
Error message
Text embedding model {self.model!r} only accepts str inputs, got {type(item).__name__}. What it means
DashScope text embedding models accept only string inputs; _call_text type-checks every element of the batch and raises ValueError on the first non-str item, reporting its type name.
Source
Thrown at src/agentscope/embedding/_dashscope/_model.py:345
self,
inputs: list[str | DataBlock],
**kwargs: Any,
) -> EmbeddingResponse:
"""Call the DashScope text embedding API for a single batch.
Args:
inputs (`list[str | DataBlock]`):
Must all be ``str``; raises ``ValueError`` otherwise.
**kwargs:
Forwarded to the API.
Returns:
`EmbeddingResponse`: Embedding vectors and usage info.
"""
texts: list[str] = []
for item in inputs:
if not isinstance(item, str):
raise ValueError(
f"Text embedding model {self.model!r} only accepts "
f"str inputs, got {type(item).__name__}.",
)
texts.append(item)
api_kwargs: dict[str, Any] = {
"input": texts,
"model": self.model,
"dimension": self.dimensions,
**kwargs,
}
if self.embedding_cache:
cached = await self.embedding_cache.retrieve(
identifier=api_kwargs,
)
if cached:
return EmbeddingResponse(View on GitHub (pinned to e90f1c7592)
Solutions
- Convert all inputs to str before calling (decode bytes, stringify paths)
- Filter or default None values to "" if your pipeline can emit them
- Use a multimodal-capable model if you need to embed images/video
Example fix
# before
vecs = await model([b"hello", "world"])
# after
vecs = await model([x.decode("utf-8") if isinstance(x, bytes) else str(x) for x in items]) Defensive patterns
Strategy: type-guard
Validate before calling
inputs = [x.decode() if isinstance(x, bytes) else x for x in inputs]
Type guard
def all_str(items: list) -> bool:\n return all(isinstance(i, str) for i in items)
Try / catch
try:\n await model(texts)\nexcept ValueError as e:\n if \"only accepts str\" in str(e): texts = [str(t) for t in texts]; await model(texts)\n else: raise
Prevention
- Normalize to str at data-ingestion boundaries
- Use a multimodal model for non-text content
When it happens
Trigger: Calling the model with a list containing non-str entries, e.g. bytes, DataBlock, dict, pathlib.Path, or None, via __call__ with text-mode inputs.
Common situations: Passing file contents read in binary mode (bytes); passing multimodal DataBlock objects to a text-only model; None values from upstream data pipelines with missing fields.
Related errors
- Invalid input: {item!r}. Expected str or DataBlock.
- DashScope text embedding API error: {response}
- DashScope multimodal embedding API error: {res}
- Multimodal embedding API only supports URL input for video d
- Unsupported media type {media_type!r} in DataBlock. Expected
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/1ed0b5bdd8432544.
Report an issue: GitHub.