Skip to content

D50 — What we believe is a table, read with read-only SQL

  • Status: Accepted
  • Date: 2026-09-23
  • Origin: slice 27 build
  • Area: reading

Decision

  • A derived table, current_values (schema 12), holds one row per value an entity holds, per relation it has (kind=relation) and per relation pointing at it (relation_in).
  • Each row has a standing: current is what we believe; unverified_update, contested, projection and rumour are the rest, kept beside it.
  • Each row carries the value as text and as a number, its unit or currency, the related entity, valid_from and since, the score, the number of independent sources, and claim_ids: the claims behind it.
  • It is computed by the same code as kg get, so the two cannot disagree; a test checks that they do not.
  • It is an index, not data. It is never staged, never exported and never in a bundle. It is rebuilt whole whenever what it rests on has changed: a new decision in reviews, another day, or a changed pack. A full rebuild of the real graph (105 sites, 1,889 rows) takes 0.3 seconds.
  • A view per type, v_<type>: one row per entity, one column per property (a number stays a number) and per outgoing edge (the related entity's name), current values only, and the claim ids behind the row.
  • kg sql "<SELECT>" (MCP read op=sql) runs one statement:
  • on a connection opened read-only, with query_only set;
  • behind an authorizer that allows reading and nothing else: no writes, no ATTACH, no PRAGMA that sets anything;
  • with a row limit (200, and it says when it cut) and a time limit (5 s);
  • with named :parameters. Every table is readable, raw claims included. kg sql --schema says which are what we believe and which are raw.
  • kg query keeps its filters and gains --columns (with the claims behind each row), --sort, --limit, --csv, and --as-of/--known-at, which it answers live, since the table is "now".
  • kg views export <file> writes the table and each type view to a standalone SQLite file, with a metadata.json holding the saved queries as Datasette canned queries. No dependency is added, and the command warns that the file may hold local-only rows.
  • A SQL answer is a pointer for research, not evidence. It cites claims; the claims cite sources.

Why

Every question so far was about one entity. "Every Texas site under construction, with its operator and power" meant a brief per site. An agent can write SQL, and a table it can read is the primitive every other question is built from: a view per type reads like a spreadsheet, and the claim ids keep each answer tied to its evidence. Read-only is enforced by SQLite, not by checking the text of the query.

Alternatives

  • Only extend kg query with flags. Every new question would need a new flag.
  • SQL views computed by SQLite from the claims. Which value is current depends on scoring, supersession and validity (D6a, D13d, D32), written in Python; duplicating it in SQL would let the two drift.
  • Serve Datasette. It needs a dependency and a server, and MCP cannot reach it. The export gives the same browsing to anyone who has it installed.