ractogateway.pipelines.sql_analyst._viz
Chart specification and deterministic Plotly figure builder.
No LLM calls — chart type is either specified by the user or inferred from DataFrame column dtypes using simple heuristics.
Requires: pip install ractogateway[pipelines-sql-viz]
- class ractogateway.pipelines.sql_analyst._viz.ChartSpec(**data)[source]
Bases:
BaseModelSpecification for a Plotly chart.
Pass to
SQLAnalystPipelineaschart=ChartSpec(...)or as a plaindict(e.g.chart={"chart_type": "bar", "x": "customer", "y": "revenue"}). Usechart="auto"to let the pipeline infer the best chart type from the DataFrame’s column dtypes with no extra LLM call.Supported chart types
bar·line·scatter·pie·histogram·box·area·heatmap·violin·funnelExample:
from ractogateway.pipelines import SQLAnalystPipeline, ChartSpec result = pipeline.run( user_query="Top 5 customers by revenue?", ..., chart=ChartSpec(chart_type="bar", x="customer_name", y="revenue", title="Top 5 Customers"), ) result.plotly_figure.show()
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- chart_type: str
- title: str
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- ractogateway.pipelines.sql_analyst._viz.build_figure(df, spec)[source]
Build a Plotly
Figurefrom df using the deterministic spec.- Parameters:
df (
Any) – A pandasDataFrameto visualise.spec (
ChartSpec) – AChartSpecdescribing chart type, axes, title, etc.
- Return type:
- Returns:
plotly.graph_objects.Figure
- Raises:
ImportError – If
plotlyis not installed.ValueError – If
spec.chart_typeis not in_CHART_MAP.
- ractogateway.pipelines.sql_analyst._viz.infer_spec(df, pd_module)[source]
Infer the best
ChartSpecfrom df column dtypes — no LLM needed.Heuristic decision tree:
datetime + numeric → line chart (trend over time)
categorical + numeric, ≤6 unique values → pie chart
categorical + numeric, >6 unique values → bar chart
2+ numeric columns → scatter plot
1 numeric column → histogram
Otherwise →
None