Skip to content

fix: GenAI Client(evals) - Scope HTML report IDs, styles, and scripts per widget in show() - #7320

Open
takumiohym wants to merge 1 commit into
googleapis:mainfrom
takumiohym:fix/evals-visualization-unique-ids
Open

takumiohym wants to merge 1 commit into
googleapis:mainfrom
takumiohym:fix/evals-visualization-unique-ids

Conversation

@takumiohym

@takumiohym takumiohym commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

In JupyterLab (and any notebook environment where multiple cell outputs share the same document DOM, unlike Google Colab which isolates each output in an <iframe>), calling .show() multiple times on EvaluationResult, EvaluationRun, EvaluationDataset, or LossAnalysisResult fails after the first report:

  • get_evaluation_html, get_comparison_html, get_inference_html, and get_loss_analysis_html emit hardcoded duplicate element IDs (#summary-section, #details-section, #results-table, #loss-analysis-root) and look them up via document.getElementById(...).
  • Every subsequent .show() call in the same notebook resolves document.getElementById(...) to the first widget's containers—overwriting the first report with the latest data while leaving all subsequent reports empty below the heading.
  • Global var vizData_vertex_eval_sdk / top-level helper functions and unscoped body / element CSS rules also leak across cells.
  • On cold notebook loads via DOM fragment insertion, the inline <script> can execute before the CDN <script src> dependencies (marked / DOMPurify) finish loading.

Minimal Reproduction (JupyterLab)

Run in a JupyterLab notebook (or across two cells):

import pandas as pd
from vertexai import types

for label in ("Report 1", "Report 2"):
    ds = types.EvaluationDataset(
        eval_dataset_df=pd.DataFrame({"prompt": ["p"], "response": [label]})
    )
    res = types.EvaluationResult(
        evaluation_dataset=[ds],
        summary_metrics=[
            types.AggregatedMetricResult(
                metric_name=f"metric_{label}", mean_score=1.0, stdev_score=0.0
            )
        ],
        eval_case_results=[
            types.EvalCaseResult(
                eval_case_index=0,
                response_candidate_results=[
                    types.ResponseCandidateResult(
                        response_index=0,
                        metric_results={
                            f"metric_{label}": types.MetricResult(score=1.0)
                        },
                    )
                ],
            )
        ],
    )
    res.show()
  • Before: The first Evaluation Report box displays metric_Report 2 (overwritten by the second .show()), and the second Evaluation Report box renders empty below the heading.
  • After: Both reports render independently with their respective metrics and case details.

Fix

Updated both vertexai/_genai/_evals_visualization.py and agentplatform/_genai/_evals_visualization.py:

  • Unique per-report IDs (uuid.uuid4().hex[:12]) for root containers and target divs (#summary-section-{uid}, #details-section-{uid}, #results-table-{uid}, #loss-analysis-root-{uid}) across all 4 HTML generators (get_evaluation_html, get_comparison_html, get_inference_html, get_loss_analysis_html).
  • IIFE isolation ((function() { ... })();) and const bindings so scripts and globals do not collide across reports.
  • Scoped CSS selectors under each report's unique root ID (including replacing bare body styling).
  • Async CDN guard & HTML-escape fallback (_runWhenReady, _sanitize, _markedParse) so reports wait briefly for DOMPurify / marked when loaded asynchronously and safely escape text if the CDN scripts are unavailable.
  • Unit tests: Added TestEvalsVisualization.test_html_reports_use_unique_ids_and_scoped_styles (parameterized across agentplatform._genai._evals_visualization and vertexai._genai._evals_visualization) in tests/unit/agentplatform/genai/test_evals.py.

Verification

  • Verified live in JupyterLab with multiple consecutive eval_result.show() calls in the same notebook (all reports render independently without overwriting earlier outputs).
  • pytest tests/unit/agentplatform/genai/test_evals.py -k "TestLossAnalysis or TestEvalsVisualization" -v: 20 passed.
  • flake8 --config=.flake8 on all 3 modified files: passed with 0 errors.

@takumiohym
takumiohym requested a review from a team as a code owner November 24, 2026 22:38
@product-auto-label product-auto-label Bot added size: xl Pull request size is extra large. api: vertex-ai Issues related to the googleapis/python-aiplatform API. labels Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: vertex-ai Issues related to the googleapis/python-aiplatform API. size: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant