BerriAI/litellm · error · ValueError

query must be a string or list of strings, got {type(query)}

Error message

query must be a string or list of strings, got {type(query)}

What it means

Raised by the query-parameter guard at the top of litellm.search: the search API only accepts a query that is a single string or a list of strings. This fires when the caller passes an int, dict, None, or any other type, before any provider request is attempted.

Source

Thrown at litellm/search/main.py:237

        )

        # Access results
        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,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Pass query as a string or a list of strings.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/search/main.py:237 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/82d477f344b2d0e5. Report an issue: GitHub.