Works

Canada Retail Market Assistant

A production-minded chat agent over Statistics Canada retail data. Ask in any language, and it writes real SQL against StatCan's retail-sales, CPI, and income tables, streams back an answer, and shows the exact query behind every number it gives you.

The project treats trustworthiness as the main feature, not an afterthought: it's built to refuse an answer rather than guess at one, and every figure it states is meant to be traceable back to a query result.

  • StackClaude Opus 5 · Sonnet 5 · Haiku, Streamlit, Neon Postgres, Grafana Cloud
  • DataStatCan monthly retail sales by NAICS (1991–2026), CPI, provincial income (~137k rows total)

🍁 Live demo: ask it something

Try the Retail Market Assistant
  • Which retail category grew fastest in 2025?
  • How do median incomes in Ontario and Quebec compare?

Strengths

What the design is willing to bet on:

+ grounded, not recalled

Every number comes from a live SQL query against StatCan tables, re-run each time, rather than from what a model remembers being trained on.

+ provenance you can click through

The SQL behind an answer sits one tap away. Not "trust me".

− memory resets with the tab

Chat history is session-only; there are no accounts yet, so nothing persists across visits.

− limits are per-session, not per-person

Without login, a new tab is a new rate-limit budget.

vs. just asking ChatGPT

A general chatbotThis assistant
Where the number comes fromTraining-time recallA live query, run fresh every time
Can you check itNo, taken on faithYes, because the SQL is shown, not claimed
When it doesn't knowTends to hedge and answer anywayRefuses, since "no data" beats a guess
ScopeBroad, shallow on any one datasetOne database, guardrails tuned to it

What a session looks like

Streaming status, a plain-language answer, SQL provenance one tap away, and a source line with a feedback control, so nothing claims a number the SQL below it didn't produce.

Which retail category grew fastest in 2025?

writing SQL against retail_sales_naics · executing · streaming answer…

Furniture & home furnishings stores grew fastest among NAICS retail categories in 2025, up 7.8% year over year, putting it ahead of motor vehicle & parts dealers (+5.1%) and food & beverage stores (+3.4%).

▸ SQL · SELECT naics_category, pct_change FROM retail_sales_yoy WHERE year = 2025 ORDER BY pct_change DESC LIMIT 5

Source: StatCan monthly retail sales by NAICS, 2026-08-31 snapshot. 👍 👎

Defense in depth

Every layer has attack-suite evidence behind it (a 21-case suite covering comment smuggling, statement splitting, and encoded literals runs in CI), and every layer has a named backstop for when it fails.

LayerDefenseBackstop if it fails
InputFP≈0 injection signatures, raw-SQL block, 3-tier rate limitsRejected free, pre-model
MoneyDaily budget breaker (process)Platform monthly spend cap
SQLLexical allowlist after comment/literal strippingEXPLAIN cost gate
ExecutionSingle-exit gateway moduleapp_ro: SELECT-only + 15s timeout
Data-sideResults wrapped in random tags, "data ≠ instructions"Worst case is still one validated SELECT
OutputImage-markdown stripped (beacon channel closed)HTML escaped by the framework
LogsSeparate DB, INSERT-only writer, parameterized writesFail-open, disclosed in the UI

How we know it's right

→ golden set, computed live

30 cases where the expected number comes from reference SQL run against the same database, rather than being hand-written, with a sample checked against official published figures.

→ behavior, not just answers

Refusals, clarifications, definition traps, and follow-up chains are graded by regex anchors plus an independent judge model (Sonnet 5), since the answering model never grades itself.

→ contamination control

Cases whose SQL appears as a few-shot example in the prompt are bucketed separately; the reported score is the uncontaminated held-out bucket.

→ a blind bucket

7 questions authored by someone who never saw the system or the data dictionary scored 6/7, and the one failure exposed three real, documented defects rather than being hidden.

Latest authored-set run: 30/30 (100% held-out), every answer under the 60-second budget, with the full replies archived so the score is inspectable, not just claimed.
© 2026 Yue Jin. All Rights Reserved.