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 chatbot | This assistant | |
|---|---|---|
| Where the number comes from | Training-time recall | A live query, run fresh every time |
| Can you check it | No, taken on faith | Yes, because the SQL is shown, not claimed |
| When it doesn't know | Tends to hedge and answer anyway | Refuses, since "no data" beats a guess |
| Scope | Broad, shallow on any one dataset | One 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.
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%).
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.
| Layer | Defense | Backstop if it fails |
|---|---|---|
| Input | FP≈0 injection signatures, raw-SQL block, 3-tier rate limits | Rejected free, pre-model |
| Money | Daily budget breaker (process) | Platform monthly spend cap |
| SQL | Lexical allowlist after comment/literal stripping | EXPLAIN cost gate |
| Execution | Single-exit gateway module | app_ro: SELECT-only + 15s timeout |
| Data-side | Results wrapped in random tags, "data ≠ instructions" | Worst case is still one validated SELECT |
| Output | Image-markdown stripped (beacon channel closed) | HTML escaped by the framework |
| Logs | Separate DB, INSERT-only writer, parameterized writes | Fail-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.