← All posts

SQL-first charts for AI and blockchain operations

A small Datasette charting release points to a larger practice: putting charts next to SQL for AI and blockchain operations. The value is speed, but only if your event design, query logic, and time handling are strict enough to keep charts honest.

Simon Willison notes a preview release of datasette-charts, a plugin for visualizing SQL query results in Datasette. The release itself is small. The bigger lesson for practitioners is older and more useful. Once charting sits next to your query engine, the distance between raw data, inspection, and action gets short.

This matters in AI systems and blockchain operations because both produce event-heavy logs. You have prompts, traces, tool calls, retries, signatures, mempool observations, RPC latencies, settlement delays, and state transitions. If your team moves those signals into a database, lightweight charting on top of SQL becomes part of your operating surface, not a reporting layer.

The risk is false comfort. A chart next to a query looks authoritative even when the query hides sampling bias, duplicate events, clock drift, or bad joins. If you use SQL-first dashboards for AI or chain telemetry, you need to inspect the shape of the data before you trust the line on the screen.

Start with event design, not the chart

Most monitoring problems start before visualization. They start in the event schema.

For AI systems, log each meaningful step as a separate event. Prompt received. Context assembled. Model called. Tool invoked. Tool result returned. Final response emitted. Include request IDs, tenant IDs, model name, latency, token counts, cache hits, and error class. Keep input and output sizes. Record timestamps at the source system, not only at the collector.

For blockchain systems, treat the chain as one source among several. Log transaction submitted, nonce assigned, RPC endpoint used, transaction hash observed, inclusion detected, confirmation depth reached, and final application settlement. If you run indexers or watchers, store reorg-related events instead of overwriting prior state.

A simple rule helps. Design for countability.

Each event should answer one of these questions:

  • What happened
  • When it happened
  • Which entity it affected
  • Which upstream action caused it
  • Whether it completed, failed, or retried

Without this, your SQL becomes guesswork. A chart of “failed calls by hour” is weak if retries and terminal failures share the same event type. A chart of “chain finality time” is weak if you only log first-seen and never log confirmation depth.

Common failure points:

  • Mutable rows in place of append-only events
  • No stable correlation ID across services
  • Timestamps generated after queue delays
  • Missing version fields when prompts, tools, or contract ABIs change
  • Aggregated counters with no raw event trail

Write SQL for operational truth

Once events land in a table, the next problem is query design. SQL charts often hide weak assumptions because the result set looks neat.

Start with raw inspection queries before aggregation. Pull 100 recent rows. Check for nulls, duplicate request IDs, impossible durations, and out-of-order timestamps. Then write the chart query.

For AI latency, avoid one wide table with one row per request if the request spans many steps. A step-event model is easier to audit.

select
  date_trunc('hour', occurred_at) as hour,
  step_name,
  percentile_disc(0.95) within group (order by duration_ms) as p95_ms,
  count(*) as n
from ai_step_events
where occurred_at >= now() - interval '24 hours'
  and status = 'ok'
group by 1, 2
order by 1, 2;

This query does two useful things. It separates steps. It keeps sample size visible with n. Without the count, a p95 chart can swing on tiny traffic.

For blockchain operations, model lifecycle durations by joining event types with care.

with submitted as (
  select request_id, tx_hash, occurred_at as submitted_at
  from chain_events
  where event_type = 'tx_submitted'
), confirmed as (
  select tx_hash, min(occurred_at) as confirmed_at
  from chain_events
  where event_type = 'tx_confirmed'
  group by tx_hash
)
select
  date_trunc('hour', s.submitted_at) as hour,
  avg(extract(epoch from (c.confirmed_at - s.submitted_at))) as avg_seconds,
  count(*) as n
from submitted s
join confirmed c using (tx_hash)
group by 1
order by 1;

This still needs scrutiny. Do multiple request IDs map to one transaction hash. Are replacements under the same nonce excluded. Did a reorg produce later invalidation. The query is a draft until those questions have answers.

Signals to read in your own SQL:

  • Groupings with no explicit timezone handling
  • Inner joins that drop failures and pending work
  • Percentiles with tiny sample sizes
  • Averages used where the distribution is long-tailed
  • Distinct counts hiding duplicate ingestion

Chart the failures, not only the happy path

Teams often chart throughput and median latency first. Those matter, but they miss the work your operators spend time on.

For AI systems, chart:

  • Tool-call error rate by tool name and version
  • Retry depth distribution
  • Token usage by model and route
  • Prompt-template version against refusal rate or fallback rate
  • Queue delay versus model execution time

For blockchain systems, chart:

  • RPC error rate by endpoint and method
  • Time from submission to first mempool observation
  • Inclusion delay by gas policy version
  • Reorg frequency by depth
  • Stuck transaction count by age bucket

These charts help you separate protocol conditions from application faults. If inclusion delay rises while mempool observation stays flat, your fee policy or transaction construction needs inspection. If tool-call latency is steady but queue delay rises, the bottleneck sits outside the model.

Where teams go wrong:

  • They collapse all errors into one series
  • They chart percentages without the underlying denominator
  • They mix client retries with server retries
  • They compare versions without tagging release boundaries
  • They treat missing data as zero

Missing data is a common source of lies in charts. Zero means something happened and the count was zero. Missing means you do not know. Keep those states separate in both SQL and visualization settings.

Account for time, skew, and replays

AI systems and blockchain systems both produce delayed and duplicated signals. Charts built on naive timestamps drift away from operational truth.

Use at least two time fields where it matters:

  • Event time, when the action happened at the source
  • Ingest time, when your store received it

Chart both when you debug pipeline quality. A widening gap between event time and ingest time means queue pressure, network issues, or source-side buffering. For blockchain indexers, replayed blocks and reorg handling often produce late-arriving corrections. If your dashboard only reads the latest materialized table, operators lose sight of correction volume.

Practical checks:

  • Compare counts by event time and ingest time per hour
  • Measure duplicate rate per source and per deploy version
  • Track clock skew by host or service
  • Flag negative durations after joins
  • Keep a replay marker on backfilled or reprocessed events

A good pattern is append-only facts plus derivations. Store the raw event log. Build summary tables from it. When your chart looks wrong, you need a path back to the original events. Without that, every incident turns into an argument about whose number is right.

Keep the dashboard close to the database, but test the queries

The appeal of SQL-first charting is speed. You write a query. You get a graph. That is useful for operators, data engineers, ML engineers, and protocol teams. It reduces handoffs.

It also moves failure risk into query logic. Treat operational SQL like code.

Do a few simple things:

  • Save queries in version control
  • Review changes to business logic in pull requests
  • Add fixtures with known edge cases
  • Test joins against duplicate and missing records
  • Record chart definitions with owners and intended use

If you expose charting to non-specialists, provide reference queries for common tasks. For example, one blessed query for p95 step latency, one for transaction confirmation delay, one for retry depth. This limits drift across teams.

If you build internal tools in Go, keep the boundary simple. Let Go handle ingestion, validation, and job control. Let SQL handle aggregation. Keep charting read-only. That split reduces the chance that a debug dashboard becomes an accidental control plane.

What to watch next

SQL-adjacent charting will keep spreading into operational tooling for AI and blockchain systems. The useful shift is not visual polish. It is shorter time from event capture to informed action.

Watch for teams to add stronger event versioning, better treatment of late data, and query tests alongside application tests. Those changes do more for reliability than another dashboard tab.