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

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.

Source

Thrown at src/agentscope/embedding/_gemini/_model.py:324

        Passes the list of strings directly to ``embed_content``,
        which returns one embedding per string.

        Args:
            inputs (`list[str | DataBlock]`):
                Must all be ``str``; raises ``ValueError`` otherwise.
            **kwargs:
                Merged into ``EmbedContentConfig`` (e.g.
                ``task_type``).

        Returns:
            `EmbeddingResponse`: Embedding vectors and usage info.
        """
        from google.genai import types

        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)

        config = types.EmbedContentConfig(
            output_dimensionality=self.dimensions,
            **kwargs,
        )

        cache_key = {
            "model": self.model,
            "contents": texts,
            "output_dimensionality": self.dimensions,
            **kwargs,
        }

        if self.embedding_cache:

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Coerce all inputs to str before calling: [str(x) if x is not None else "" for x in inputs]
  2. Filter or skip None/empty entries before embedding
  3. If you meant to embed images/audio, use a multimodal-capable model config so _call_multimodal is used instead of _call_text

Example fix

# before
embs = await model(inputs=["a", 42, None])

# after
inputs = [str(x) for x in ["a", 42, None] if x is not None]
embs = await model(inputs=inputs)
Defensive patterns

Strategy: type-guard

Validate before calling

inputs = [x for x in inputs if isinstance(x, str) and x]
# or coerce: inputs = [str(x) for x in inputs]

Type guard

def all_str(inputs: list) -> bool:
    return all(isinstance(x, str) for x in inputs)

Try / catch

try:
    embs = await model(inputs=inputs)
except ValueError as e:
    if "only accepts str inputs" in str(e):
        inputs = [str(x) for x in inputs if x is not None]
        embs = await model(inputs=inputs)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/1b01bdc5f061ab49. Report an issue: GitHub.