BerriAI/litellm · error · ValueError

Missing required fields in the result={result}

Error message

Missing required fields in the result={result}

What it means

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.

Source

Thrown at litellm/llms/hosted_vllm/rerank/transformation.py:192

    def _transform_response(self, response: dict) -> RerankResponse:
        # Extract usage information
        usage_data: Final = response.get("usage", {})
        _billed_units: Final = RerankBilledUnits(total_tokens=usage_data.get("total_tokens", 0))
        _tokens: Final = RerankTokens(input_tokens=usage_data.get("total_tokens", 0))
        rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)

        # Extract results
        _results: Final[list[dict] | None] = response.get("results")

        if _results is None:
            raise ValueError(f"No results found in the response={response}")

        rerank_results: Final[list[RerankResponseResult]] = []

        for result in _results:
            # Validate required fields exist
            if not all(key in result for key in ["index", "relevance_score"]):
                raise ValueError(f"Missing required fields in the result={result}")

            # Get document data if it exists
            document_data = result.get("document", {})
            document = RerankResponseDocument(text=str(document_data.get("text", ""))) if document_data else None

            # Create typed result
            rerank_result = RerankResponseResult(
                index=int(result["index"]),
                relevance_score=float(result["relevance_score"]),
            )

            # Only add document if it exists
            if document:
                rerank_result["document"] = document

            rerank_results.append(rerank_result)

        return RerankResponse(

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Check the offending result object embedded in the message to see which field names your server actually returns.
  2. Point the call at a server emitting vLLM's native rerank schema (results[] with index and relevance_score), or update/align vLLM version.
  3. If your server uses a different schema, either adapt its response in a small proxy or use a provider transformation that matches its format.
  4. Report/patch upstream if standard vLLM genuinely omits a field for some request type (e.g. top_n=0 edge cases).
Defensive patterns

Strategy: validation

Validate before calling

null  # response-side; guard by preflighting schema

# reuse is_vllm_rerank_payload from a one-off probe call to lock the schema before traffic

Type guard

def is_valid_rerank_result(result: dict) -> bool:
    return isinstance(result, dict) and "index" in result and "relevance_score" in result

Try / catch

try:
    result = litellm.rerank(...)
except ValueError as e:
    if "Missing required fields in the result" in str(e):
        # schema mismatch between your rerank server and vLLM-native format — fix server/adaptor
        raise RuntimeError("rerank server schema mismatch; expected index+relevance_score per result") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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').

Related errors


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