{"record":{"id":"9fd8c300ba6375d2","repo":"BerriAI/litellm","slug":"missing-required-fields-in-the-result-result-9fd8c3","errorCode":null,"errorMessage":"Missing required fields in the result={result}","messagePattern":"Missing required fields in the result=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/together_ai/rerank/transformation.py","lineNumber":36,"sourceCode":"\n\nclass TogetherAIRerankConfig:\n    def _transform_response(self, response: dict) -> RerankResponse:\n        _billed_units: Final = RerankBilledUnits(**response.get(\"usage\", {}))\n        _tokens: Final = RerankTokens(**response.get(\"usage\", {}))\n        rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)\n\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":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/together_ai/rerank/transformation.py#L18-L54","documentation":"While iterating TogetherAI rerank results, LiteLLM requires each item in 'results' to contain at least 'index' and 'relevance_score'. If any element is missing either key (e.g. items reduced to {'document': ...} only, or null entries), this ValueError is raised with the offending result serialized in the message. It is a per-item schema validation of the provider payload.","triggerScenarios":"Together returns results entries lacking index or relevance_score (partial fields on certain models/modes); response-mocking tools that build plausible but incomplete items; downstream API version drift where scores are omitted (e.g. return_documents-only responses).","commonSituations":"Test fixtures hand-written from docs that skip optional-looking fields; Together A/B response formats; gateway transforms that strip fields; llm-judge pipelines consuming raw Together output.","solutions":["Check the result object printed in the message to identify the missing field(s).","If you control the response source (mock/stub), include 'index' and 'relevance_score' in every result item.","Update litellm to the latest patch in case the provider's format changed and was adapted upstream.","If Together genuinely omits scores for your model, switch to a rerank model id documented to return them."],"exampleFix":"# before — stub result missing required fields\n# body: {\"results\": [{\"document\": {\"text\": \"...\"}}]}\nresp = litellm.rerank(model=\"together_ai/rerank-english-v2.0\", query=q, documents=docs)\n# ValueError: Missing required fields in the result={'document': {'text': '...'}}\n\n# after — each item carries index + relevance_score\n# body: {\"results\": [\n#   {\"index\": 0, \"relevance_score\": 0.97, \"document\": {\"text\": \"...\"}}\n# ]}","handlingStrategy":"try-catch","validationCode":"def valid_rerank_results(results) -> bool:\n    \"\"\"Validate item shape before handing payloads to code that assumes it.\"\"\"\n    if not isinstance(results, list):\n        return False\n    return all(\n        isinstance(r, dict) and \"index\" in r and \"relevance_score\" in r\n        for r in results\n    )","typeGuard":"def is_complete_rerank_result(item: object) -> bool:\n    \"\"\"Type guard for a single Together rerank result item.\"\"\"\n    return (\n        isinstance(item, dict)\n        and isinstance(item.get(\"index\"), int)\n        and isinstance(item.get(\"relevance_score\"), (int, float))\n    )","tryCatchPattern":"try:\n    resp = litellm.rerank(model=\"together_ai/rerank-english-v2.0\", query=q, documents=docs)\nexcept ValueError as e:\n    if \"Missing required fields in the result\" in str(e):\n        logger.error(\"together rerank item malformed: %s\", e)\n        resp = litellm.rerank(model=\"together_ai/rerank-english-v2.0\", query=q, documents=docs[:50])\n    else:\n        raise","preventionTips":["Keep fixtures schema-exact: every result needs index and relevance_score.","Add a response-shape contract test for each rerank provider you use.","Upgrade litellm promptly when Together changes response formats."],"tags":["together-ai","rerank","response-parsing","schema-validation","litellm"],"backgroundTag":"unexpected-api-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}