Logic Foundry

Build with understanding.

Chartify’s agent ranked regions by revenue. Why did the chart show them alphabetically?

Asked to show revenue across eight regions, Chartify’s AI agent recommended a horizontal bar chart with the highest-revenue region first. The chart instead began with ANZ and ended with Other. Inspecting the agent’s recommendation would not have caught the bug: it explicitly said sort_order: "descending".

Chartify’s developer traced the discrepancy to the Streamlit app, not the agent. The renderer had reversed its ascending and descending conditions, and its category axis did not preserve the order of the rows supplied to it. The fix changed both the rendering code and what the developer chose to test.

Give the agent a decision it can check

Chartify uses a Snowflake Cortex Agent guided by 15 rules covering chart selection, ordering, color, emphasis and captions. The rules pair a decision with its exceptions. For regional revenue, sorting bars by value makes the ranking visible. For signup rates by weekday, the same sort would obscure the weekly pattern, so the rule preserves Monday-to-Sunday order.

Chartify’s agent ranked regions by revenue. Why did the chart show them alphabetically? (1)

Some choices are deliberately conventional rather than universal. For a part-to-whole question, Chartify allows a pie chart with up to three categories and uses a stacked bar for four or five. The developer chose those thresholds to make the behavior explicit and testable, not because the visualization literature establishes a cutoff at three.

An earlier implementation made one structured model call using hand-written column descriptions. It could recommend a chart but could not inspect the values. The agent version has three tools:

Chartify’s agent ranked regions by revenue. Why did the chart show them alphabetically? (2)
  1. chartify_analyst uses Cortex Analyst and a Snowflake semantic view to turn the question into SQL and query the data.
  2. validate_recommendation checks whether the proposed chart fits the data. For example, it can check that a proposed correlation heatmap has enough numeric columns. If validation fails, the agent gets one opportunity to revise its proposal.
  3. submit_chart_recommendation returns structured settings, including the chart type, sort order, highlight, caption and IDs of the rules the agent says it used.

The app checks the submission before drawing anything. In one development run, the request returned HTTP 200 even though the agent had called neither the validator nor the submission tool. For a missing, failed, duplicate, truncated or malformed submission, the app retains the conversation and offers a retry rather than guessing at a configuration.

Make the axis order explicit

For the revenue chart, sorting the DataFrame was necessary but insufficient. The developer also passed the ordered region names to the Vega-Lite category axis:

Chartify’s agent ranked regions by revenue. Why did the chart show them alphabetically? (3)
sorted_region = by_region.sort_values(
    "revenue", ascending=False, kind="stable"
)
spec = {
    "mark": "bar",
    "encoding": {
        "x": {"field": "revenue", "type": "quantitative",
              "scale": {"zero": True}},
        "y": {"field": "region", "type": "nominal",
              "sort": sorted_region["region"].tolist()},
    },
}

The stable sort preserves the input order for regions tied on revenue. The y encoding then tells Vega-Lite exactly where to place each region, while the revenue axis retains a zero baseline. An earlier fix using st.bar_chart(..., sort=False) worked locally but failed in deployment because the deployed Streamlit version did not support that argument. The explicit Vega-Lite order worked in the deployed app.

Chartify’s agent ranked regions by revenue. Why did the chart show them alphabetically? (4)

Check the chart inputs separately from the agent’s claims

Chartify’s Best Practice tab lists the rules the agent cites. Its Evaluation tab uses Python and Pandas to inspect the plotted data and, for Vega-Lite charts, the final specification after styling. For native Streamlit charts, it can inspect the data and explicit API arguments, but not the visual encodings ultimately resolved by the browser.

That distinction exposed another mismatch. In a weekday signup test, the agent chose to highlight the lowest day even though the user had not requested a highlight. Snowflake’s DAYNAME() returned Sun, while the local plotting data used Sunday. The bars appeared in the correct calendar order, but none matched the highlight. The evaluator warned that Sun was absent from the encoded categories. The developer identified the app’s styling step as the place to match abbreviated and full weekday names; the warning itself did not repair the chart.

Chartify’s agent ranked regions by revenue. Why did the chart show them alphabetically? (5)

The example illustrates a boundary of the demo: the agent queries Snowflake, but the renderer plots local sample data selected by chart type. It does not draw arbitrary Cortex Analyst query results. A general-purpose implementation would need to carry the selected data, filters and aggregations through to the renderer and verify that they answer the question.

The developer reported 63 passing local tests and exercised all 11 supported chart and table types through Streamlit’s AppTest with mocked agent calls. Deployed browser checks were narrower: the developer inspected the regional revenue chart in a dark theme, not every chart across themes and viewport sizes.

Evaluation therefore reports individual results as Pass, Fail, Not Applicable or Not Checked, rather than combining them into a score. The app can verify that a caption exists, for instance, without claiming that its account of the data is accurate. Likewise, a passing sort check says the bars are in the intended order—not that the labels are legible or that the chart answers the reader’s question.