Recipes / Data & reports
CodexWorkflowData & reports

Explore, clean and chart a dataset with a coding agent

A workshop handout for data journalists: use Claude Code or Codex to ask questions of a database, clean messy codes, build visualizations and scrape data.

Setup time30 min
CostPay-per-token (the workshop spent $23 total)
RunsPer dataset
NeedsCodex or Claude Code, Python, SQLite, Datasette (optional)
Last updated2026-10-15
BlogSource

Coding agents for data analysis

by Simon Willison · 2026-03-16

✓ Opened with WebFetch on 2026-10-15

Read the original ↗
Part 1 · What the source did

A workshop handout for data journalists: use Claude Code or Codex to ask questions of a database, clean messy codes, build visualizations and scrape data.

  • Ran a 3-hour workshop on GitHub Codespaces with a budget-restricted Codex key.
  • Had attendees query SQLite, decode neighborhood codes and scrape with agents.
  • Served a viz/ folder through Datasette and had Claude Code build an interactive Leaflet heat map there.

Summary written by Agent Cookbook. See the original for the full context.

Part 2 · Our copy-paste version

Adapted by us from what the source described. Fill in the [BRACKETS].

The prompt

You have [DATABASE.db] (SQLite). Work only in this folder. 1. List the tables and describe each in one line. Show 5 sample rows from the most important one. 2. Answer: [QUESTION]. Show the SQL you ran and the result. 3. Find columns with codes or messy values and propose a cleaning plan. Don't modify the original; write a cleaned copy. 4. Build one static HTML visualization in viz/ that answers the question. Use a CDN library, no build step.
🛡
Approval ruleThe agent writes to a copy; the original data file stays read-only.

Set it up

  1. Put the data in a fresh folder or Codespace.
  2. Set a spending cap on the API key if you use one.
  3. Run the prompt step by step and check the SQL yourself.
  4. Open the viz file locally.

Common failures

⚠
What usually goes wrong
  • Agents state numbers confidently; always ask for the query behind a figure.
  • Scraping steps may break site terms. Check before running.

Variations

  • Point Datasette at viz/ so new charts show up live.
  • Use the same flow for spreadsheets exported to CSV.

Related recipes