BerriAI/litellm · error · ValueError
input must be a string or a list
Error message
input must be a string or a list
What it means
Guard inside CachingHandler's kwargs-input normalization helper: the value passed for the model input is neither a string nor a list, so it cannot be normalized into the list-of-strings form the caching layer expects.
Solutions
- Pass input as a string or a list of strings to the embedding/caching call.
- Validate the input type before invoking litellm.embedding so non-string, non-list values are rejected early.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/caching/caching_handler.py:378 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/5dccdfbfbf453379.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/caching/caching_handler.py:378
self.preset_cache_key
or self.request_kwargs.get("cache_key")
or litellm.cache.get_cache_key(**self.request_kwargs)
)
if hasattr(cached_result, "_hidden_params"):
cached_result._hidden_params["cache_key"] = cache_key
return CachingHandlerResponse(cached_result=cached_result)
return CachingHandlerResponse(cached_result=cached_result)
def handle_kwargs_input_list_or_str(self, kwargs: dict[str, Any]) -> list[str]:
"""
Handles the input of kwargs['input'] being a list or a string
"""
if isinstance(kwargs["input"], str):
return [kwargs["input"]]
elif isinstance(kwargs["input"], list):
return kwargs["input"]
else:
raise ValueError("input must be a string or a list")
def _extract_model_from_cached_results(self, non_null_list: list[tuple[int, CachedEmbedding]]) -> str | None:
"""
Helper method to extract the model name from cached results.
Args:
non_null_list: List of (idx, cr) tuples where cr is the cached result dict
Returns:
Optional[str]: The model name if found, None otherwise
"""
for _, cr in non_null_list:
if isinstance(cr, dict) and cr.get("model"):
return cr["model"]
return None
def _process_async_embedding_cached_response(
self,View on GitHub (pinned to 77b7c6c40c)