BerriAI/litellm · error · ValueError
Missing required fields in the result={result}
Error message
Missing required fields in the result={result} What it means
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.
Source
Thrown at litellm/llms/together_ai/rerank/transformation.py:36
class TogetherAIRerankConfig:
def _transform_response(self, response: dict) -> RerankResponse:
_billed_units: Final = RerankBilledUnits(**response.get("usage", {}))
_tokens: Final = RerankTokens(**response.get("usage", {}))
rerank_meta: Final = RerankResponseMeta(billed_units=_billed_units, tokens=_tokens)
_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 77b7c6c40c)
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.
Example fix
# before — stub result missing required fields
# body: {"results": [{"document": {"text": "..."}}]}
resp = litellm.rerank(model="together_ai/rerank-english-v2.0", query=q, documents=docs)
# ValueError: Missing required fields in the result={'document': {'text': '...'}}
# after — each item carries index + relevance_score
# body: {"results": [
# {"index": 0, "relevance_score": 0.97, "document": {"text": "..."}}
# ]} Defensive patterns
Strategy: try-catch
Validate before calling
def valid_rerank_results(results) -> bool:
"""Validate item shape before handing payloads to code that assumes it."""
if not isinstance(results, list):
return False
return all(
isinstance(r, dict) and "index" in r and "relevance_score" in r
for r in results
) Type guard
def is_complete_rerank_result(item: object) -> bool:
"""Type guard for a single Together rerank result item."""
return (
isinstance(item, dict)
and isinstance(item.get("index"), int)
and isinstance(item.get("relevance_score"), (int, float))
) Try / catch
try:
resp = litellm.rerank(model="together_ai/rerank-english-v2.0", query=q, documents=docs)
except ValueError as e:
if "Missing required fields in the result" in str(e):
logger.error("together rerank item malformed: %s", e)
resp = litellm.rerank(model="together_ai/rerank-english-v2.0", query=q, documents=docs[:50])
else:
raise Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- No results found in the response={response}
- No results found in the response={response}
- Missing required fields in the result={result}
- TogetherAI does not support max_chunks_per_doc
- response.text
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/9fd8c300ba6375d2.
Report an issue: GitHub.