BerriAI/litellm · error · ValueError

All items in query list must be strings

Error message

All items in query list must be strings

What it means

Validation guard in litellm.search: query was accepted as a list, but at least one element is not a string (e.g. an int or nested list slipped in). The whole list is rejected before the search call is dispatched.

Source

Thrown at litellm/search/main.py:240

        for result in response.results:
            print(f"{result.title}: {result.url}")
            print(f"Snippet: {result.snippet}")
            if result.date:
                print(f"Date: {result.date}")
        ```
    """
    local_vars: Final = locals()
    try:
        litellm_logging_obj: Final[LiteLLMLoggingObj] = kwargs.pop("litellm_logging_obj")
        litellm_call_id: Final[str | None] = kwargs.get("litellm_call_id", None)
        _is_async: Final = kwargs.pop("asearch", False) is True

        # Validate query parameter
        if not isinstance(query, (str, list)):
            raise ValueError(f"query must be a string or list of strings, got {type(query)}")

        if isinstance(query, list) and not all(isinstance(q, str) for q in query):
            raise ValueError("All items in query list must be strings")

        # Get provider config
        search_provider_config: Final[BaseSearchConfig | None] = ProviderConfigManager.get_provider_search_config(
            provider=SearchProviders(search_provider),
        )

        if search_provider_config is None:
            raise ValueError(f"Search is not supported for provider: {search_provider}")

        verbose_logger.debug("Search call - provider: %s", search_provider)

        # Build optional_params from explicit parameters
        optional_params: Final = _build_search_optional_params(
            max_results=max_results,
            search_domain_filter=search_domain_filter,
            max_tokens_per_page=max_tokens_per_page,
            country=country,
        )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Pass a list of strings as the query, e.g. query=['term1','term2'] instead of mixing in numbers or dicts.
  2. Coerce each item with str() before calling, or validate the list with all(isinstance(q, str) for q in query).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/search/main.py:240 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/50293d2823269d34. Report an issue: GitHub.