BerriAI/litellm · error · ValueError
Missing required fields in the result={result}
Error message
Missing required fields in the result={result} What it means
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.
Source
Thrown at litellm/llms/fireworks_ai/rerank/transformation.py:224
_billed_units: Final = RerankBilledUnits(search_units=usage.get("total_tokens", 0))
_tokens: Final = RerankTokens(
input_tokens=usage.get("prompt_tokens", 0),
output_tokens=usage.get("completion_tokens", 0),
)
rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)
# Extract results - Fireworks AI uses "data" instead of "results"
_results: Final[list[dict] | None] = raw_response_json.get("data") or raw_response_json.get("results")
if _results is None:
raise ValueError(f"No results found in the response={raw_response_json}")
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 - Fireworks AI returns document as a string directly
document_text = result.get("document")
document = None
if document_text:
# Handle both string and object formats
if isinstance(document_text, str):
document = RerankResponseDocument(text=document_text)
elif isinstance(document_text, dict):
# Handle object format if it exists
text = document_text.get("text", "")
if text:
document = RerankResponseDocument(text=str(text))
# Create typed result
rerank_result = RerankResponseResult(
index=int(result["index"]),
relevance_score=float(result["relevance_score"]),View on GitHub (pinned to 6c2dcb801b)
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.
Example fix
# before (fixture with Cohere-style keys)
{"data": [{"index": 0, "score": 0.9}]}
# after
{"data": [{"index": 0, "relevance_score": 0.9}]} Defensive patterns
Strategy: type-guard
Validate before calling
def validate_rerank_fixture(results: list[dict]) -> bool:
return all(
isinstance(r, dict) and "index" in r and "relevance_score" in r
for r in results
) Type guard
def is_wellformed_rerank_result(result: object) -> bool:
return (
isinstance(result, dict)
and isinstance(result.get("index"), int)
and isinstance(result.get("relevance_score"), (int, float))
) Try / catch
try:
litellm.rerank(model="fireworks_ai/...", query=q, documents=docs)
except ValueError as e:
if "Missing required fields" in str(e):
logging.error("Malformed rerank item from provider: %s", e)
raise RuntimeError("Fireworks rerank schema drift detected") from e
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No results found in the response={response}
- query is required for Fireworks AI rerank
- documents is required for Fireworks AI rerank
- No results found in the response={raw_response_json}
- query is required for DashScope rerank
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/b03f872eb6dd442f.
Report an issue: GitHub.