Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Evidentlyai Evidently Legacy Base Renderer

From Leeroopedia
Knowledge Sources
Domains ML Monitoring, Rendering, Visualization
Last Updated 2026-02-14 12:00 GMT

Overview

Legacy Base Renderer defines the base classes and infrastructure for rendering metrics and tests as HTML, JSON, and pandas DataFrames in the Evidently legacy reporting system.

Description

This module provides the foundational rendering architecture for the Evidently legacy pipeline. The key classes and components are:

BaseRenderer -- the base class for all renderers. It holds a color_options attribute (defaulting to ColorOptions()) that controls visualization colors.

MetricRenderer (Generic[TMetric]) -- a generic renderer for metrics that provides three rendering methods:

  • render_pandas(obj) -- converts the metric result to a pd.DataFrame. Issues a warning if the metric does not support DataFrame output.
  • render_json(obj, include_render, include, exclude) -- converts the metric result to a dictionary.
  • render_html(obj) -- returns a list of BaseWidgetInfo objects for HTML rendering. This is abstract and raises NotImplementedError.

TestRenderer (Generic[TTest]) -- a generic renderer for tests that provides:

  • html_description(obj) / json_description(obj) -- extract the test result description.
  • render_html(obj) -- returns a TestHtmlInfo object containing the test name, description, status, fingerprint, details, and groups.
  • render_json(obj, ...) -- converts the test result to a dictionary.

DetailsInfo -- a Pydantic model for detail entries with a title, info (widget or any), and auto-generated UUID7 ID.

TestHtmlInfo -- a Pydantic model for HTML-rendered test information containing name, description, test_fingerprint, status, details list, and groups dictionary. Has a with_details(title, info) method for fluent detail appending.

RenderersDefinitions -- a dataclass that holds a registry of typed renderers and default renderers for tests and metrics.

default_renderer(wrap_type) -- a decorator that registers a renderer class in the DEFAULT_RENDERERS global registry for a given metric/test type.

DEFAULT_RENDERERS -- the global RenderersDefinitions instance initialized with a default TestRenderer.

WidgetIdGenerator -- generates unique hierarchical widget IDs based on a base ID and an incrementing counter, with optional postfix support.

Utility functions:

  • replace_widgets_ids(widgets, generator) -- replaces IDs on a list of widgets.
  • replace_test_widget_ids(widget, generator) -- replaces IDs on test detail widgets.
  • replace_widget_ids(widget, generator) -- recursively replaces IDs on a widget, its additional graphs, nested widgets, and updates internal ID references in params.

Usage

Use these base classes when implementing custom metric or test renderers for the Evidently legacy reporting system. Extend MetricRenderer or TestRenderer and register with the @default_renderer decorator.

Code Reference

Source Location

Signature

class BaseRenderer:
    color_options: ColorOptions
    def __init__(self, color_options: Optional[ColorOptions] = None) -> None: ...

class MetricRenderer(Generic[TMetric], BaseRenderer):
    def render_pandas(self, obj: TMetric) -> pd.DataFrame: ...
    def render_json(self, obj: TMetric, include_render=False, include=None, exclude=None) -> dict: ...
    def render_html(self, obj: TMetric) -> List[BaseWidgetInfo]: ...

class TestRenderer(Generic[TTest], BaseRenderer):
    def html_description(self, obj: TTest): ...
    def json_description(self, obj: TTest): ...
    def render_html(self, obj: TTest) -> TestHtmlInfo: ...
    def render_json(self, obj: TTest, include_render=False, include=None, exclude=None) -> dict: ...

class DetailsInfo(BaseModel):
    title: str
    info: Union[BaseWidgetInfo, Any]
    id: str = Field(default_factory=lambda: str(uuid6.uuid7()))

class TestHtmlInfo(BaseModel):
    name: str
    description: str
    test_fingerprint: str
    status: str
    details: List[DetailsInfo]
    groups: Dict[str, str]
    def with_details(self, title: str, info: BaseWidgetInfo): ...

@dataclasses.dataclass
class RenderersDefinitions:
    typed_renderers: dict = dataclasses.field(default_factory=dict)
    default_html_test_renderer: Optional[TestRenderer] = None
    default_html_metric_renderer: Optional[MetricRenderer] = None

def default_renderer(wrap_type): ...

DEFAULT_RENDERERS = RenderersDefinitions(default_html_test_renderer=TestRenderer())

class WidgetIdGenerator:
    def __init__(self, base_id: str): ...
    def get_id(self, postfix: str = None) -> str: ...

def replace_widgets_ids(widgets, generator): ...
def replace_test_widget_ids(widget, generator): ...
def replace_widget_ids(widget, generator): ...

Import

from evidently.legacy.renderers.base_renderer import BaseRenderer
from evidently.legacy.renderers.base_renderer import MetricRenderer
from evidently.legacy.renderers.base_renderer import TestRenderer
from evidently.legacy.renderers.base_renderer import TestHtmlInfo, DetailsInfo
from evidently.legacy.renderers.base_renderer import RenderersDefinitions, DEFAULT_RENDERERS
from evidently.legacy.renderers.base_renderer import default_renderer
from evidently.legacy.renderers.base_renderer import WidgetIdGenerator
from evidently.legacy.renderers.base_renderer import replace_widgets_ids, replace_widget_ids

I/O Contract

Inputs

Name Type Required Description
color_options Optional[ColorOptions] No Color options for visualization. Defaults to ColorOptions().
obj (render_html) TMetric or TTest Yes The metric or test instance to render.
include_render bool No Whether to include render data in JSON output. Default: False.
include IncludeOptions No Fields to include in JSON output.
exclude IncludeOptions No Fields to exclude from JSON output.

Outputs

Name Type Description
render_html (MetricRenderer) List[BaseWidgetInfo] List of widget info objects for HTML rendering.
render_html (TestRenderer) TestHtmlInfo Test HTML info object with name, description, status, and details.
render_json dict Dictionary representation of the metric or test result.
render_pandas pd.DataFrame Pandas DataFrame representation of the metric result.

Usage Examples

from evidently.legacy.renderers.base_renderer import MetricRenderer, default_renderer
from evidently.legacy.model.widget import BaseWidgetInfo

# Register a custom metric renderer
@default_renderer(wrap_type=MyCustomMetric)
class MyCustomMetricRenderer(MetricRenderer):
    def render_html(self, obj):
        result = obj.get_result()
        return [
            BaseWidgetInfo(
                type="counter",
                title="My Metric",
                size=2,
                params={"counters": [{"value": str(result.value), "label": "Value"}]},
            )
        ]

# Use WidgetIdGenerator for unique IDs
from evidently.legacy.renderers.base_renderer import WidgetIdGenerator, replace_widgets_ids

generator = WidgetIdGenerator(base_id="report-1")
widgets = my_renderer.render_html(my_metric)
replace_widgets_ids(widgets, generator)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment