mlflow/mlflow · error · MlflowException
No retrieval context found in the trace. The RetrievalGround
Error message
No retrieval context found in the trace. The RetrievalGroundedness scorer requires the trace to contain at least one span with type 'RETRIEVER'.
What it means
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.
Source
Thrown at mlflow/genai/scorers/builtin_scorers.py:776
def __call__(self, *, trace: Trace) -> list[Feedback]:
"""
Evaluate groundedness of response against retrieved context.
Args:
trace: The trace of the model's execution. Must contains at least one span with
type `RETRIEVER`. MLflow will extract the retrieved context from that span.
If multiple spans are found, MLflow will use the **last** one.
Returns:
An :py:class:`mlflow.entities.assessment.Feedback~` object with a boolean value
indicating the groundedness of the response.
"""
request = extract_request_from_trace(trace)
response = extract_response_from_trace(trace)
span_id_to_context = extract_retrieval_context_from_trace(trace)
if not span_id_to_context:
raise MlflowException(
"No retrieval context found in the trace. The RetrievalGroundedness "
"scorer requires the trace to contain at least one span with type 'RETRIEVER'."
)
feedbacks = []
for span_id, context in span_id_to_context.items():
feedback = judges.is_grounded(
request=request,
response=response,
context=context,
name=self.name,
model=self.model,
extra_headers=self.extra_headers,
)
feedback.span_id = span_id
feedbacks.append(feedback)
return feedbacks
View on GitHub (pinned to 6a27f2decc)
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
Example fix
// before
mlflow.genai.evaluate(data=traces, scorers=[RetrievalGroundedness()]) # traces have no RETRIEVER span
// after
with mlflow.start_span(name='retriever', span_type=mlflow.entities.SpanType.RETRIEVER) as span:
docs = vectorstore.similarity_search(query)
span.set_attributes({'mlflow.traceAttributes.retrieval': [mlflow.doc_attr(d) for d in docs]})
mlflow.genai.evaluate(data=rag_traces, scorers=[RetrievalGroundedness()]) Defensive patterns
Strategy: validation
Validate before calling
def has_retrieval_context(trace):
return any(getattr(s, 'span_type', None) == 'RETRIEVER' for s in trace.data.spans)
if not has_retrieval_context(trace):
raise ValueError('Trace lacks RETRIEVER span; RetrievalGroundedness cannot run') Type guard
def is_rag_trace(trace) -> bool:
return bool(trace) and any(getattr(s, 'span_type', None) == 'RETRIEVER' for s in trace.data.spans) Try / catch
from mlflow.exceptions import MlflowException
try:
feedbacks = RetrievalGroundedness()(trace=trace)
except MlflowException as e:
if 'No retrieval context found' in str(e):
feedbacks = None # mark row as not-applicable for groundedness
else:
raise Prevention
- 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)
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No retrieval context found in the trace. The RetrievalSuffic
- No retrieval context found in the trace. The RetrievalReleva
- INVALID_PARAMETER_VALUE
- No suitable adapter found for model_uri='{model_uri}'. Some
- InputPassFail has no Databricks counterpart; Databricks-rout
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/3ac404de2b7e2175.
Report an issue: GitHub.