Skip to content

API Reference

vizro_ai.agents

Vizro-AI agents.

This module contains pre-configured Pydantic AI agents. Below you can find a list of all agents available and their respective response models/types instructions. For more information on how to use those agents, see the Pydantic AI agents documentation.

chart_agent module-attribute

chart_agent = Agent[DataFrame, BaseChartPlan](deps_type=DataFrame, output_type=BaseChartPlan, instructions='You are an expert in plotly data visualization. You are given a user request and you need to generate plotly\nchart code.')

vizro_ai.agents.response_models

BaseChartPlan

Bases: BaseModel

Base chart plan used to generate chart code based on user visualization requirements.

chart_function property

chart_function

Return a callable function that generates a pure Plotly chart.

Example
chart_func = result.output.chart_function
fig = chart_func(df, x="sepal_width")

Returns:

Type Description
Callable[..., Figure]

A callable function that accepts data_frame and **kwargs and returns a go.Figure object.

code property

code

Get the generated chart code as a pure Plotly code string.

code_vizro property

code_vizro

Get the generated chart code formatted for use in Vizro dashboards.

vizro_chart_function property

vizro_chart_function

Return a callable function that generates a Vizro-compatible chart.

Example
vizro_func = result.output.vizro_chart_function
fig = vizro_func(df, x="sepal_width")

Returns:

Type Description
Callable[..., Figure]

A callable function that accepts data_frame and **kwargs and returns a go.Figure object.

get_chart_function

get_chart_function(chart_name, vizro)

Return a callable function with customizable name and vizro flag.

This method returns a reusable function that can be called with a dataframe and optional keyword arguments. The function name and Vizro compatibility can be customized.

Parameters:

Name Type Description Default
chart_name str

Name of the chart function.

required
vizro bool

Whether to generate Vizro-compatible code.

required

Returns:

Type Description
Callable[..., Figure]

A callable function that accepts data_frame and **kwargs and returns a go.Figure object.

Example
chart_func = result.output.get_chart_function(chart_name="my_chart", vizro=True)
fig = chart_func(df, x="sepal_width")

ChartPlan

Bases: BaseChartPlan

Extended chart plan model with additional explanatory fields.

ChartPlanFactory

__new__

__new__(data_frame, chart_plan=ChartPlan)

Creates a chart plan model that executes the chart code as part of the model validation.

Parameters:

Name Type Description Default
data_frame DataFrame

DataFrame to use for validation

required
chart_plan type[BaseChartPlan]

Chart plan model to run extended validation against.

ChartPlan

Returns:

Type Description
type[BaseChartPlan]

Chart plan model with additional validation