BerriAI/litellm · warning · ValueError

No results found in the response={raw_response_json}

Error message

No results found in the response={raw_response_json}

What it means

Intended to signal an Infinity rerank response with no 'results' array, but as written it is dead code: cohere_results is initialized to [] and can never be None, so the ValueError is unreachable. An empty or missing results field instead yields a RerankResponse with an empty results list.

Source

Thrown at litellm/llms/infinity/rerank/transformation.py:108

            output_tokens=(
                raw_response_json.get("usage", {}).get("total_tokens", 0)
                - raw_response_json.get("usage", {}).get("prompt_tokens", 0)
            ),
        )
        rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)

        cohere_results: Final[list[RerankResponseResult]] = []
        if raw_response_json.get("results"):
            for result in raw_response_json.get("results"):
                _rerank_response = RerankResponseResult(
                    index=result.get("index"),
                    relevance_score=result.get("relevance_score"),
                )
                if result.get("document"):
                    _rerank_response["document"] = RerankResponseDocument(text=result.get("document"))
                cohere_results.append(_rerank_response)
        if cohere_results is None:
            raise ValueError(f"No results found in the response={raw_response_json}")

        return RerankResponse(
            id=raw_response_json.get("id") or str(uuid.uuid4()),
            results=cohere_results,
            meta=rerank_meta,
        )  # Return response

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Do not rely on this error — check the returned RerankResponse.results length yourself.
  2. If you need the exception, patch the transformation to test raw_response_json.get('results') instead.
  3. Upstream contribution: change the guard to `if not raw_response_json.get('results'):` to match the Jina behavior.

Example fix

# before (library, dead code)
cohere_results = []
...
if cohere_results is None:
    raise ValueError(...)

# after (caller-side guard)
resp = litellm.rerank(model='infinity/...', query=q, documents=docs, api_base=...)
if not resp.results:
    logger.warning('infinity rerank returned no results')
Defensive patterns

Strategy: type-guard

Validate before calling

def has_results(rerank_response) -> bool:
    results = getattr(rerank_response, 'results', None)
    return bool(results)

Type guard

def is_non_empty_rerank_response(obj: object) -> bool:
    return hasattr(obj, 'results') and isinstance(obj.results, list) and len(obj.results) > 0

Prevention

When it happens

Trigger: Cannot currently be triggered by any input — the guard `if cohere_results is None` follows an assignment of a list literal, so it never fires. Compare with the Jina config, which correctly checks `_results is None` from the JSON.

Common situations: Developers reading the code expect an exception on empty Infinity rerank results and are surprised to get results=[]; this matters when asserting on exception behavior in tests or error handling.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/36dc461555355c26. Report an issue: GitHub.