Skip to content

mlflow.genai.evaluate(): handle case where root span is unavailable#19220

Merged
BenWilson2 merged 5 commits intomlflow:masterfrom
dbczumar:root_span_miss
Dec 4, 2025
Merged

mlflow.genai.evaluate(): handle case where root span is unavailable#19220
BenWilson2 merged 5 commits intomlflow:masterfrom
dbczumar:root_span_miss

Conversation

@dbczumar
Copy link
Collaborator

@dbczumar dbczumar commented Dec 4, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19220/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/19220/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/19220/merge

Related Issues/PRs

#xxx

What changes are proposed in this pull request?

mlflow.genai.evaluate(): handle case where root span is unavailable. This can happen for partial third-party OTel traces or if the user calls search_traces(include_spans=False) and then tries to pass the resulting traces to eval.

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How should the PR be classified in the release notes? Choose one:

  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Should this PR be included in the next patch release?

Yes should be selected for bug fixes, documentation updates, and other small changes. No should be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.

What is a minor/patch release?
  • Minor release: a release that increments the second part of the version number (e.g., 1.2.0 -> 1.3.0).
    Bug fixes, doc updates and new features usually go into minor releases.
  • Patch release: a release that increments the third part of the version number (e.g., 1.2.0 -> 1.2.1).
    Bug fixes and doc updates usually go into patch releases.
  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

Add None check before accessing root span inputs/outputs to prevent
AttributeError. Warn when traces are missing root spans but keep them
in the dataset for downstream processing.

Signed-off-by: dbczumar <corey.zumar@databricks.com>
Add None check before accessing root span inputs/outputs to prevent
AttributeError. Warn when traces are missing root spans but keep them
in the dataset for downstream processing.

Signed-off-by: dbczumar <corey.zumar@databricks.com>
Copilot AI review requested due to automatic review settings December 4, 2025 18:55
@github-actions github-actions bot added the v3.7.0 label Dec 4, 2025
@dbczumar dbczumar requested a review from AveshCSingh December 4, 2025 18:55
@github-actions github-actions bot added area/evaluation MLflow Evaluation rn/none List under Small Changes in Changelogs. labels Dec 4, 2025
assert transformed_data["inputs"].isna().all()


def test_convert_to_eval_set_with_missing_root_span():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On master, this fails with:

Traceback (most recent call last):
  File "/Users/corey.zumar/mlflowrepos/mlflow4/find_jarvis_issues.py", line 112, in <module>
    main()
  File "/Users/corey.zumar/mlflowrepos/mlflow4/find_jarvis_issues.py", line 86, in main
    issues = find_issues(
  File "/Users/corey.zumar/mlflowrepos/mlflow4/insights.py", line 431, in find_issues
    mlflow.genai.evaluate(
  File "/Users/corey.zumar/mlflowrepos/mlflow4/mlflow/genai/evaluation/base.py", line 248, in evaluate
    df = _convert_to_eval_set(data)
  File "/Users/corey.zumar/mlflowrepos/mlflow4/mlflow/genai/evaluation/utils.py", line 121, in _convert_to_eval_set
    .pipe(_extract_request_response_from_trace)
  File "/Users/corey.zumar/miniconda3/envs/mlflow/lib/python3.10/site-packages/pandas/core/generic.py", line 6253, in pipe
    return common.pipe(self, func, *args, **kwargs)
  File "/Users/corey.zumar/miniconda3/envs/mlflow/lib/python3.10/site-packages/pandas/core/common.py", line 502, in pipe
    return func(obj, *args, **kwargs)
  File "/Users/corey.zumar/mlflowrepos/mlflow4/mlflow/genai/evaluation/utils.py", line 185, in _extract_request_response_from_trace
    df["inputs"] = df["trace"].apply(lambda trace: trace.data._get_root_span().inputs)
  File "/Users/corey.zumar/miniconda3/envs/mlflow/lib/python3.10/site-packages/pandas/core/series.py", line 4943, in apply
    ).apply()
  File "/Users/corey.zumar/miniconda3/envs/mlflow/lib/python3.10/site-packages/pandas/core/apply.py", line 1422, in apply
    return self.apply_standard()
  File "/Users/corey.zumar/miniconda3/envs/mlflow/lib/python3.10/site-packages/pandas/core/apply.py", line 1502, in apply_standard
    mapped = obj._map_values(
  File "/Users/corey.zumar/miniconda3/envs/mlflow/lib/python3.10/site-packages/pandas/core/base.py", line 925, in _map_values
    return algorithms.map_array(arr, mapper, na_action=na_action, convert=convert)
  File "/Users/corey.zumar/miniconda3/envs/mlflow/lib/python3.10/site-packages/pandas/core/algorithms.py", line 1743, in map_array
    return lib.map_infer(values, mapper, convert=convert)
  File "pandas/_libs/lib.pyx", line 2999, in pandas._libs.lib.map_infer
  File "/Users/corey.zumar/mlflowrepos/mlflow4/mlflow/genai/evaluation/utils.py", line 185, in <lambda>
    df["inputs"] = df["trace"].apply(lambda trace: trace.data._get_root_span().inputs)
AttributeError: 'NoneType' object has no attribute 'inputs'

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds defensive handling for cases where the root span is unavailable in mlflow.genai.evaluate(), preventing potential AttributeErrors when traces are fetched without spans (e.g., using search_traces(..., include_spans=False)).

  • Introduces a _safe_extract_from_root_span helper function that safely checks for None root spans before accessing attributes
  • Adds a warning when traces without root spans are detected to inform users about the issue
  • Includes comprehensive test coverage for the missing root span scenario

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
mlflow/genai/evaluation/utils.py Adds _safe_extract_from_root_span helper function to safely handle None root spans and logs warnings when traces lack root spans
tests/genai/evaluate/test_utils.py Adds test case test_convert_to_eval_set_with_missing_root_span to verify correct handling of traces without root spans

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)

# Warn about traces that don't have a root span (where inputs/outputs are None)
missing_count = df[["inputs", "outputs"]].isna().any(axis=1).sum()
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning logic counts rows where either inputs or outputs is None, but the warning message suggests it's specifically about missing root spans. When a root span is missing, both inputs and outputs will be None. Consider using .all(axis=1) instead of .any(axis=1) to only count rows where both are None, which would more accurately identify traces without root spans:

missing_count = df[["inputs", "outputs"]].isna().all(axis=1).sum()

This would avoid false positives where a trace has a root span but only one of inputs or outputs is None.

Suggested change
missing_count = df[["inputs", "outputs"]].isna().any(axis=1).sum()
missing_count = df[["inputs", "outputs"]].isna().all(axis=1).sum()

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Documentation preview for bc7ea8a is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

Add None check before accessing root span inputs/outputs to prevent
AttributeError. Warn when traces are missing root spans but keep them
in the dataset for downstream processing.

Signed-off-by: dbczumar <corey.zumar@databricks.com>
Signed-off-by: dbczumar <corey.zumar@databricks.com>
Signed-off-by: dbczumar <corey.zumar@databricks.com>
Copy link
Member

@BenWilson2 BenWilson2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good guard.

@BenWilson2 BenWilson2 added this pull request to the merge queue Dec 4, 2025
Merged via the queue into mlflow:master with commit 35d0705 Dec 4, 2025
48 of 50 checks passed
BenWilson2 pushed a commit to BenWilson2/mlflow that referenced this pull request Dec 4, 2025
BenWilson2 pushed a commit that referenced this pull request Dec 4, 2025
…19220)

Signed-off-by: dbczumar <corey.zumar@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/evaluation MLflow Evaluation rn/none List under Small Changes in Changelogs. v3.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants