{"record":{"id":"b03f872eb6dd442f","repo":"BerriAI/litellm","slug":"missing-required-fields-in-the-result-result","errorCode":null,"errorMessage":"Missing required fields in the result={result}","messagePattern":"Missing required fields in the result=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/fireworks_ai/rerank/transformation.py","lineNumber":224,"sourceCode":"        _billed_units: Final = RerankBilledUnits(search_units=usage.get(\"total_tokens\", 0))\n        _tokens: Final = RerankTokens(\n            input_tokens=usage.get(\"prompt_tokens\", 0),\n            output_tokens=usage.get(\"completion_tokens\", 0),\n        )\n        rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)\n\n        # Extract results - Fireworks AI uses \"data\" instead of \"results\"\n        _results: Final[list[dict] | None] = raw_response_json.get(\"data\") or raw_response_json.get(\"results\")\n\n        if _results is None:\n            raise ValueError(f\"No results found in the response={raw_response_json}\")\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 - Fireworks AI returns document as a string directly\n            document_text = result.get(\"document\")\n            document = None\n            if document_text:\n                # Handle both string and object formats\n                if isinstance(document_text, str):\n                    document = RerankResponseDocument(text=document_text)\n                elif isinstance(document_text, dict):\n                    # Handle object format if it exists\n                    text = document_text.get(\"text\", \"\")\n                    if text:\n                        document = RerankResponseDocument(text=str(text))\n\n            # Create typed result\n            rerank_result = RerankResponseResult(\n                index=int(result[\"index\"]),\n                relevance_score=float(result[\"relevance_score\"]),","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/fireworks_ai/rerank/transformation.py#L206-L242","documentation":"For each item in the Fireworks rerank results array, litellm requires the fields 'index' and 'relevance_score' to construct a RerankResponseResult. An item missing either key raises ValueError echoing that specific result object, pinpointing exactly which entry in the response was malformed.","triggerScenarios":"A Fireworks (or mocked) response whose data/results entries omit 'index' or 'relevance_score' — e.g. fields renamed to 'score'/'rank', null entries, or a partially truncated response body.","commonSituations":"Fireworks ships a schema tweak; a gateway re-serializes and drops fields; test fixtures hand-write results with Cohere-style keys ('relevance_score' vs 'score') so the per-item validation fails.","solutions":["Look at the echoed result object in the message to identify which field is absent or renamed.","Upgrade (or pin) litellm to the release matching the Fireworks rerank schema you are targeting.","Fix test fixtures/mocks to include both 'index' (int) and 'relevance_score' (float) on every result item."],"exampleFix":"# before (fixture with Cohere-style keys)\n{\"data\": [{\"index\": 0, \"score\": 0.9}]}\n\n# after\n{\"data\": [{\"index\": 0, \"relevance_score\": 0.9}]}","handlingStrategy":"type-guard","validationCode":"def validate_rerank_fixture(results: list[dict]) -> bool:\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_wellformed_rerank_result(result: object) -> bool:\n    return (\n        isinstance(result, dict)\n        and isinstance(result.get(\"index\"), int)\n        and isinstance(result.get(\"relevance_score\"), (int, float))\n    )","tryCatchPattern":"try:\n    litellm.rerank(model=\"fireworks_ai/...\", query=q, documents=docs)\nexcept ValueError as e:\n    if \"Missing required fields\" in str(e):\n        logging.error(\"Malformed rerank item from provider: %s\", e)\n        raise RuntimeError(\"Fireworks rerank schema drift detected\") from e\n    raise","preventionTips":["When mocking Fireworks rerank, generate fixtures from a recorded real response, not hand-written dicts.","Pin litellm versions in lockfiles and review provider changelogs before upgrading Fireworks-dependent code.","Assert on result shape in one place (a normalizer) so schema drift surfaces as a single clear error."],"tags":["fireworks-ai","rerank","response-parsing","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}