{"record":{"id":"8a4a2391e0476889","repo":"BerriAI/litellm","slug":"missing-required-fields-in-the-result-result-8a4a23","errorCode":null,"errorMessage":"Missing required fields in the result={result}","messagePattern":"Missing required fields in the result=(.+?)","errorType":"http","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/hosted_vllm/rerank/transformation.py","lineNumber":192,"sourceCode":"    def _transform_response(self, response: dict) -> RerankResponse:\n        # Extract usage information\n        usage_data: Final = response.get(\"usage\", {})\n        _billed_units: Final = RerankBilledUnits(total_tokens=usage_data.get(\"total_tokens\", 0))\n        _tokens: Final = RerankTokens(input_tokens=usage_data.get(\"total_tokens\", 0))\n        rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)\n\n        # Extract results\n        _results: Final[list[dict] | None] = response.get(\"results\")\n\n        if _results is None:\n            raise ValueError(f\"No results found in the response={response}\")\n\n        rerank_results: Final[list[RerankResponseResult]] = []\n\n        for result in _results:\n            # Validate required fields exist\n            if not all(key in result for key in [\"index\", \"relevance_score\"]):\n                raise ValueError(f\"Missing required fields in the result={result}\")\n\n            # Get document data if it exists\n            document_data = result.get(\"document\", {})\n            document = RerankResponseDocument(text=str(document_data.get(\"text\", \"\"))) if document_data else None\n\n            # Create typed result\n            rerank_result = RerankResponseResult(\n                index=int(result[\"index\"]),\n                relevance_score=float(result[\"relevance_score\"]),\n            )\n\n            # Only add document if it exists\n            if document:\n                rerank_result[\"document\"] = document\n\n            rerank_results.append(rerank_result)\n\n        return RerankResponse(","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/hosted_vllm/rerank/transformation.py#L174-L210","documentation":"Raised in HostedVLLM RerankConfig._transform_response when an entry inside response['results'] is missing 'index' or 'relevance_score'. The parser requires both fields to construct a RerankResponseResult (it casts result['index'] to int and result['relevance_score'] to float), so any malformed entry aborts the whole response conversion.","triggerScenarios":"A rerank server whose results use a different schema — e.g. {'id','score'} (Cohere-style is index/relevance_score, but other servers use 'corpus_id'/'score' à la sentence-transformers, or omit index). Triggered by pointing hosted_vllm rerank at a non-vLLM or customized rerank service, or a vLLM fork/version that renames fields.","commonSituations":"Self-hosted reranker behind a custom adapter layer; vLLM fork with modified rerank response format; version skew between the deployed vLLM and LiteLLM's expected schema ('index' + 'relevance_score').","solutions":["Check the offending result object embedded in the message to see which field names your server actually returns.","Point the call at a server emitting vLLM's native rerank schema (results[] with index and relevance_score), or update/align vLLM version.","If your server uses a different schema, either adapt its response in a small proxy or use a provider transformation that matches its format.","Report/patch upstream if standard vLLM genuinely omits a field for some request type (e.g. top_n=0 edge cases)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"null  # response-side; guard by preflighting schema\n\n# reuse is_vllm_rerank_payload from a one-off probe call to lock the schema before traffic","typeGuard":"def is_valid_rerank_result(result: dict) -> bool:\n    return isinstance(result, dict) and \"index\" in result and \"relevance_score\" in result","tryCatchPattern":"try:\n    result = litellm.rerank(...)\nexcept ValueError as e:\n    if \"Missing required fields in the result\" in str(e):\n        # schema mismatch between your rerank server and vLLM-native format — fix server/adaptor\n        raise RuntimeError(\"rerank server schema mismatch; expected index+relevance_score per result\") from e\n    raise","preventionTips":["Pin vLLM and LiteLLM versions together in deployment so response schemas stay aligned.","If a custom rerank adapter sits in front, add a test asserting each result contains index and relevance_score."],"tags":["hosted-vllm","rerank","response-schema","validation","version-skew"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}