{"record":{"id":"3ac404de2b7e2175","repo":"mlflow/mlflow","slug":"no-retrieval-context-found-in-the-trace-the-retri-3ac404","errorCode":null,"errorMessage":"No retrieval context found in the trace. The RetrievalGroundedness scorer requires the trace to contain at least one span with type 'RETRIEVER'.","messagePattern":"No retrieval context found in the trace\\. The RetrievalGroundedness scorer requires the trace to contain at least one span with type 'RETRIEVER'\\.","errorType":"error_code","errorClass":"MlflowException","httpStatus":400,"severity":"error","filePath":"mlflow/genai/scorers/builtin_scorers.py","lineNumber":776,"sourceCode":"    def __call__(self, *, trace: Trace) -> list[Feedback]:\n        \"\"\"\n        Evaluate groundedness of response against retrieved context.\n\n        Args:\n            trace: The trace of the model's execution. Must contains at least one span with\n                type `RETRIEVER`. MLflow will extract the retrieved context from that span.\n                If multiple spans are found, MLflow will use the **last** one.\n\n        Returns:\n            An :py:class:`mlflow.entities.assessment.Feedback~` object with a boolean value\n            indicating the groundedness of the response.\n        \"\"\"\n        request = extract_request_from_trace(trace)\n        response = extract_response_from_trace(trace)\n        span_id_to_context = extract_retrieval_context_from_trace(trace)\n\n        if not span_id_to_context:\n            raise MlflowException(\n                \"No retrieval context found in the trace. The RetrievalGroundedness \"\n                \"scorer requires the trace to contain at least one span with type 'RETRIEVER'.\"\n            )\n\n        feedbacks = []\n        for span_id, context in span_id_to_context.items():\n            feedback = judges.is_grounded(\n                request=request,\n                response=response,\n                context=context,\n                name=self.name,\n                model=self.model,\n                extra_headers=self.extra_headers,\n            )\n            feedback.span_id = span_id\n            feedbacks.append(feedback)\n        return feedbacks\n","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/genai/scorers/builtin_scorers.py#L758-L794","documentation":"RetrievalGroundedness judges whether the agent's final response is supported by the retrieved documents, so it needs retrieval context extracted from RETRIEVER spans in the trace. When extract_retrieval_context_from_trace returns an empty mapping, there is no context to ground against and __call__ raises this MlflowException.","triggerScenarios":"Calling RetrievalGroundedness()(trace=...) (directly or inside mlflow.genai.evaluate) with a trace lacking any span of type RETRIEVER — non-RAG traces, traces where retrieval happened outside traced code, or retriever spans whose attributes don't carry document content.","commonSituations":"Same root cause as RetrievalSufficiency: autolog not enabled for the retrieval framework, custom retrieval code not annotated with span_type='RETRIEVER', running evaluate() over a mixed dataset containing non-RAG traces, or upgrading MLflow and old traces lacking retriever span attributes.","solutions":["Record retrieval with a RETRIEVER span: `with mlflow.start_span(span_type=SpanType.RETRIEVER)` and attach documents via span attributes (`mlflow.doc_attr` / retrieval attributes)","Enable framework autolog (e.g. `mlflow.langchain.autolog()`, `mlflow.openai.autolog()`) so retrieval spans are captured automatically","Filter the evaluation dataset to traces containing retriever spans: `any(s.span_type == 'RETRIEVER' for s in trace.data.spans)`","Pick a scorer that doesn't need retrieval context (Correctness, Guidelines, ExpectationsGuidelines) if your pipeline has no retrieval step"],"exampleFix":"// before\nmlflow.genai.evaluate(data=traces, scorers=[RetrievalGroundedness()])  # traces have no RETRIEVER span\n\n// after\nwith mlflow.start_span(name='retriever', span_type=mlflow.entities.SpanType.RETRIEVER) as span:\n    docs = vectorstore.similarity_search(query)\n    span.set_attributes({'mlflow.traceAttributes.retrieval': [mlflow.doc_attr(d) for d in docs]})\nmlflow.genai.evaluate(data=rag_traces, scorers=[RetrievalGroundedness()])","handlingStrategy":"validation","validationCode":"def has_retrieval_context(trace):\n    return any(getattr(s, 'span_type', None) == 'RETRIEVER' for s in trace.data.spans)\n\nif not has_retrieval_context(trace):\n    raise ValueError('Trace lacks RETRIEVER span; RetrievalGroundedness cannot run')","typeGuard":"def is_rag_trace(trace) -> bool:\n    return bool(trace) and any(getattr(s, 'span_type', None) == 'RETRIEVER' for s in trace.data.spans)","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    feedbacks = RetrievalGroundedness()(trace=trace)\nexcept MlflowException as e:\n    if 'No retrieval context found' in str(e):\n        feedbacks = None  # mark row as not-applicable for groundedness\n    else:\n        raise","preventionTips":["Record retrieved documents as attributes on a RETRIEVER-type span (use mlflow.doc_attr)","Enable autologging for your agent framework to capture retrieval spans","Validate trace shape before scoring: at least one span_type == 'RETRIEVER'","Use scorer suites that tolerate missing retrieval (catch and substitute a fallback scorer)"],"tags":["mlflow","genai","rag","trace","groundedness"],"backgroundTag":"missing-retriever-span-in-trace","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}