Expand description
Schema introspection — turn an open Connection (or raw
Database) into the textual schema dump the LLM uses to ground
its SQL generation.
§Why we don’t SELECT FROM sqlrite_master
The sqlrite_master catalog persists the original CREATE TABLE
SQL, so reflecting via SQL would work. But we already have the
same information typed in Database.tables — going through SQL
would mean parsing the round-tripped CREATE statement a second
time. Walking the typed structure is cheaper and matches what
the engine considers authoritative right now (relevant inside
an open transaction, where the persisted catalog may already be
stale relative to the in-memory snapshot).
§Determinism (matters for prompt caching)
Tables are dumped in alphabetical order, columns in declaration
order. The output is byte-stable for a fixed schema — that’s
what lets cache_control: ephemeral actually hit on repeat
calls. Any change to the format invalidates the cache once for
everyone, but steady-state hits are cheap.
Functions§
- dump_
schema_ for_ connection - Render the schema of every user-visible table on
connas a sequence ofCREATE TABLE … (…);statements, sorted alphabetically by table name. - dump_
schema_ for_ database - Same as
dump_schema_for_connection, but takes aDatabasereference directly. Used by the REPL’s.askmeta-command (which holds&Database, not&Connection).