{"record":{"id":"36dc461555355c26","repo":"BerriAI/litellm","slug":"no-results-found-in-the-response-raw-response-jso-36dc46","errorCode":null,"errorMessage":"No results found in the response={raw_response_json}","messagePattern":"No results found in the response=(.+?)","errorType":"http","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"litellm/llms/infinity/rerank/transformation.py","lineNumber":108,"sourceCode":"            output_tokens=(\n                raw_response_json.get(\"usage\", {}).get(\"total_tokens\", 0)\n                - raw_response_json.get(\"usage\", {}).get(\"prompt_tokens\", 0)\n            ),\n        )\n        rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)\n\n        cohere_results: Final[list[RerankResponseResult]] = []\n        if raw_response_json.get(\"results\"):\n            for result in raw_response_json.get(\"results\"):\n                _rerank_response = RerankResponseResult(\n                    index=result.get(\"index\"),\n                    relevance_score=result.get(\"relevance_score\"),\n                )\n                if result.get(\"document\"):\n                    _rerank_response[\"document\"] = RerankResponseDocument(text=result.get(\"document\"))\n                cohere_results.append(_rerank_response)\n        if cohere_results is None:\n            raise ValueError(f\"No results found in the response={raw_response_json}\")\n\n        return RerankResponse(\n            id=raw_response_json.get(\"id\") or str(uuid.uuid4()),\n            results=cohere_results,\n            meta=rerank_meta,\n        )  # Return response\n","sourceCodeStart":90,"sourceCodeEnd":115,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/infinity/rerank/transformation.py#L90-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Do not rely on this error — check the returned RerankResponse.results length yourself.","If you need the exception, patch the transformation to test raw_response_json.get('results') instead.","Upstream contribution: change the guard to `if not raw_response_json.get('results'):` to match the Jina behavior."],"exampleFix":"# before (library, dead code)\ncohere_results = []\n...\nif cohere_results is None:\n    raise ValueError(...)\n\n# after (caller-side guard)\nresp = litellm.rerank(model='infinity/...', query=q, documents=docs, api_base=...)\nif not resp.results:\n    logger.warning('infinity rerank returned no results')","handlingStrategy":"type-guard","validationCode":"def has_results(rerank_response) -> bool:\n    results = getattr(rerank_response, 'results', None)\n    return bool(results)","typeGuard":"def is_non_empty_rerank_response(obj: object) -> bool:\n    return hasattr(obj, 'results') and isinstance(obj.results, list) and len(obj.results) > 0","tryCatchPattern":null,"preventionTips":["Never rely on this library exception — it is unreachable dead code","Check response.results length explicitly after every infinity rerank call","File/upvote an upstream issue to fix the guard"],"tags":["infinity","rerank","dead-code","logic-bug","response-format"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}