Charts, Not Hand-Drawn SVG: Teaching a Model Which Visual to Use
ChatShell Team,
Ask ChatShell how a stock did over the last six months and the answer now comes with a chart.
Getting here took more than adding a chart library. ChatShell’s replies could already include Markdown tables, math, Mermaid diagrams, and SVG figures. Charts made five ways to show something visual, and that created a problem we hadn’t expected: the model kept choosing the wrong one.
Too many formats, competing instructions
Each format came with its own instructions in the prompt, and each set of instructions said, in effect, “use me.” The model received several competing invitations and picked between them inconsistently. One question got a table, a similar one got a hand-drawn chart.
The hand-drawn charts were the worst case. Asked for a bar chart, a model would write an SVG and calculate every bar’s coordinates itself. That costs a lot of output tokens, and the arithmetic is often wrong. A bar labeled 42 would be drawn taller than one labeled 58. Nothing looks more authoritative than a chart, so a wrong chart is worse than no chart.
One set of routing rules
We replaced the separate instructions with one set of routing rules. The model asks a few questions in order and stops at the first match:
- Will you click, choose, or type into it? Then it’s text. Charts in a reply only display data, so questions and options are written out.
- Is it numbers?
- Worth seeing as a shape (a trend, a comparison, a share of a whole): a chart.
- Headline metrics: KPI cards.
- A handful of exact values to read, not see: a table.
- Is it a formula? Math.
- Is it boxes joined by arrows? A Mermaid diagram, which lays itself out. Hand-placing boxes in SVG falls apart beyond eight to ten nodes.
- Is it a picture: a shape, a layout, a mockup, a rough map, an animated process? An SVG figure.
- Otherwise, text. A visual that only restates the sentence above it is left out.
The most important rule is a negative one: never draw a chart in SVG. If the chart component isn’t available, the model writes a table instead.
Charts where the app does the drawing
ChatShell’s charts are built with OpenUI, a compact language for generating interface components as a reply streams. The model writes a short block naming the chart type and the data. The app draws it.
That division is the whole point. The model only has to get the numbers right, which it’s reasonably good at. The app handles the coordinates, axes, and scaling, which it’s perfect at. ChatShell supports bar, line, area, pie, radar, and radial charts, plus rows of KPI cards such as Revenue $48.2k, +8.1% vs last month.
We kept the chart vocabulary to four components: a chart, a series, a row of stats, and a stat. Anything Markdown already renders, such as tables, headings, and code, stays in Markdown. The instructions for all of it are written by hand and cost about 600 tokens per request. The generic prompt that OpenUI’s own chat library generates is about 53 KB. A test fails if our hand-written instructions drift from what the components actually accept.
You can turn charts off in Settings → Visuals if you’d rather not spend those tokens. With them off, the model is told to use tables.
Charts that tell the truth about small changes
Version 0.10.1 tuned how charts are drawn:
- Line charts fit their axis to the data instead of starting at zero, so a stock moving from 180 to 195 doesn’t look like a flat line. Bar and area charts keep a zero baseline, because their height is the value.
- Dates are spaced by date. Points with dated labels are placed by time, with month, year, or day ticks, so a gap in the data looks like a gap.
- Units show on ticks and tooltips, such as a currency or a short suffix.
- Straight segments between points, and single-series line charts label their first and last values.
One palette for everything
Each format used to pick its own colors: the charts used one library’s defaults, the figures derived theirs from the app’s accent, and Mermaid diagrams sat on a white panel even in dark mode.
Now charts, figures, and diagrams share one palette of six colors in a fixed order. The same color holds the same position everywhere, in light and dark mode. Every color keeps at least a 3:1 contrast against the background, and pairs that color-blind readers often confuse are never next to each other.
Synced conversations
A conversation written on the Mac can be read on the iPhone app, which doesn’t draw charts or Mermaid diagrams yet. Each format has a readable fallback there: diagrams show as code with a note that they display on desktop. And when a chart carries the answer, the model also writes the chart’s conclusion in one line of text, so the answer is never only in a chart a device can’t draw.
The routing instructions are also built from what the device can actually display. The iPhone app isn’t told about charts, so it doesn’t get replies full of them.
Safety
Visuals are content from a model, so we treat them as untrusted:
- Mermaid runs in its strict security mode.
- SVG figures are shown as images, so nothing inside them can run or load anything from the internet.
- Charts and KPI cards only display data. Nothing in them opens links or sends anything.
Getting good charts
A few tips from the Charts and Diagrams guide:
- Ask for a chart if you want one. “Show me a chart of…” works better than hoping.
- Say “one” to get one. “One map showing all three days” gets a single map.
- Ask the model to check its numbers. A chart is only as right as its data. For prices and dates, add “check that each date matches its value.”
Charts and KPI cards arrived in ChatShell 0.10, with the chart refinements in 0.10.1.