SQLsage · Database intelligence

Your database,
understood.

SQLsage reads your schema, maps every relationship, turns plain questions into validated SQL and tells you what your data model is missing. It runs in your infrastructure, connects read-only, and works with the model you choose.

  • PostgreSQL first
  • Read-only by construction
  • Self-hosted
  • TypeScript SDK
Fig. 01 · The SQLsage symbol in liquid chrome

Prologue

Every database is a story nobody wrote down.

It starts the same way everywhere. A product ships, a schema grows, and every table records a decision someone made on an ordinary afternoon. Three years later there are 140 tables, two naming conventions, a column called status that means four different things, and one engineer who remembers why.

The data is all there. The meaning is not. Questions that should take a minute take a ticket. Dashboards rest on guesses about how tables join. Performance problems are found by customers first.

SQLsage reads that story back to you, accurately, and helps you write the next chapter.

The problem, stated plainly

  1. Schema knowledge lives in people, not in systems.
  2. Relationships are implied by naming more often than enforced by constraints.
  3. Ad hoc questions require both SQL fluency and tribal context.
  4. Design and performance issues surface late, in production.
01Connect

It begins with a key that can only read.

You hand SQLsage a connection string for a role that can read and nothing else. Within seconds it walks the system catalogs: every table, column, key, index, row estimate and size.

It does not read your rows to do this. It reads the shape of your data, not the data itself.

Input
PostgreSQL connection string for a read-only role
Captured
Tables, columns, types, primary and foreign keys, indexes, row estimates, on-disk size
Not captured
Row data
Source
pg_catalog and information_schema
Output
A versioned SchemaSnapshot
zsh · sqlsage
$ sqlsage inspect --url $SQLSAGE_DATABASE_URL
✓ Connected as sqlsage_readonly (read-only)
✓ Snapshot captured in 412 ms

demo_saas  10 tables · 9 relationships · 14 indexes

TABLE                     COLS        ROWS
public.events               5   8,214,330
public.audit_log            4     320,118
public.invoices             6      61,204
public.payments             5      59,877
public.customers            5       5,412
… 5 more
02Understand

Then it draws the map, and marks which roads are real.

Tables become nodes and relationships become edges. Foreign keys are drawn as verified fact.

Where a column like account_id clearly points somewhere but no constraint exists, SQLsage draws that too, as a dashed line with a confidence score and the reason behind it. A guess is never presented as a fact.

Verified edges
Declared foreign key constraints · confidence 1.0
Inferred edges
Column name and key type agreement · confidence 0.5 to 0.8
Traversal
Shortest join path between any two tables
Scoping
N-hop neighborhoods keep model context small and relevant
accountsidPKnameplan_idFKcustomersidPKaccount_idFKemailinvoicesidPKcustomer_idFKamount_centspaymentsidPKinvoice_idFKstatuseventsidPKaccount_idFKtype
Verified · foreign key constraint Inferred · 80% confidence
03Ask

Now anyone can ask, and every answer shows its work.

A product lead types a question in plain English. SQLsage finds the relevant tables, follows the verified join path and writes the query.

Before anything touches the database, the SQL is checked against strict rules. It then runs inside a read-only transaction with a timeout and a row limit, and the result comes back with an explanation and its caveats.

Pipeline
Scope → generate → validate → execute → explain
Validation
Single statement, SELECT or WITH only, no writes, no row locks, no unsafe functions
Execution
Read-only transaction · statement timeout · row limit
Recovery
Up to two regenerations when validation fails
Question

Which customers generated the most revenue last quarter?

Plan
customers→invoicesverified join
SQLValidated · read-only
select c.name, sum(i.amount_cents) / 100.0 as revenue
from public.customers c
join public.invoices i on i.customer_id = c.id
where i.paid_at >= date_trunc('quarter', now()) - interval '3 months'
  and i.paid_at <  date_trunc('quarter', now())
group by c.name
order by revenue desc
limit 3
Result3 rows · 38 ms
namerevenue
Northwind Labs$184,220.00
Acme Freight$151,904.50
Halcyon Health$122,375.25
Explanation

Revenue is concentrated: these three accounts produced 31% of paid invoices last quarter.

Caveat · refunds are not modelled, so figures are gross.

04Advise

It notices what is missing, and says how sure it is.

Tell SQLsage you are building a subscription product and it reviews the schema with that in mind: no status history for churn analysis, an unindexed foreign key on a large table, a log with no primary key.

Every suggestion carries its evidence. Measured findings come from catalogs and statistics; speculative ones are labelled as such. Nothing is applied without you.

Checks
Missing primary keys, unindexed join columns, undeclared relationships, naming drift
Use-case review
Model-assisted suggestions scoped to a stated product type
Evidence
Measured or speculative, on every item
Changes
DDL is proposed and explained, never executed
Recommendations4 open · 0 applied
High
public.audit_log has no primary key
Measured
Medium
Index public.invoices (customer_id)create index concurrently on public.invoices (customer_id);
Measured
Low
Track subscription status history for churn
Speculative
Info
Declare events.account_id as a foreign key
Speculative
05Decide

Finally, it helps you choose what to measure.

From your schema and your use case, SQLsage proposes the metrics your data can genuinely support, each with a reason and a query ready to run.

Not a generic dashboard. A starting point built on your own tables.

Input
A use case in plain language
Output
Up to six metrics, each with rationale and validated SQL
Constraint
Only metrics the current schema can answer
Trial to paid conversion
27.2%
+3.1 pts vs previous 8 weeks
Net revenue retention
112%
+4 pts vs previous 8 weeks
Accounts at risk
38
−6 vs previous 8 weeks

Specification

The details, stated formally.

SQLsage is a TypeScript platform built around one reusable core. Every interface is a thin layer over the same intelligence, so the SDK never has to call the web API to analyze a schema.

§1 Product formats
FormatBest forPriority
Web appSchema graph, chat, recommendations and query explorerBuild first
Node.js SDKIntegrate SQLsage into your own products and agentsAlongside core
CLIInspect a database from the terminal and run AI analysisEarly
Self-hosted serverKeep metadata, queries and AI processing in your infrastructureCore capability
VS Code extensionExplore schemas and ask questions inside the editorLater
§2 Architecture
  1. L1InterfacesWeb app · CLI · Node.js SDK
  2. L2SQLsage CoreSchema introspection · Metadata graph · Query planning · Recommendations
  3. L3AI orchestrationSchema analyst · SQL agent · Performance advisor · Business analyst
  4. L4Database adaptersPostgreSQL · MySQL (planned) · SQLite (planned)
  5. L5Your databaseAccessed through a read-only role. Never uploaded.
§3 Repository
apps/webNext.js dashboard
apps/marketingThis site
apps/serverNestJS API
apps/cliTerminal interface
packages/coreSQL validation, deterministic advisor, schema description
packages/aiModel providers and agents
packages/graphSchema graph, inferred relationships, traversal
packages/adapter-postgresPostgreSQL introspection and guarded execution
packages/sdkPublic Node.js SDK
packages/sharedTypes and guardrail defaults
§4 Using the SDK
import { SQLsage, AnthropicProvider } from "@sqlsage/sdk";

const sage = new SQLsage({
  database: process.env.DATABASE_URL,
  provider: new AnthropicProvider(),
  guardrails: { egress: "schema", rowLimit: 500 },
});

const { sql, result } = await sage.ask("Weekly active accounts by plan");

Security model

Your data does not have to leave.

The application and its metadata run in your infrastructure. SQLsage never requires uploading your database to an AI provider, and you decide exactly what may cross the boundary.

§5 Egress policy
PolicySchema metadata leavesQuery results leaveTypical use
noneNoNoLocal models only; regulated environments
schemaYesNoDefault; hosted models see structure, never values
schema+resultsYesYesHosted models may explain returned rows
§6 Guarantees
G-01

Read-only access

SQLsage connects through a read-only role and wraps every query in a read-only transaction.

G-02

Validated SQL

Statements are rejected unless they are a single SELECT or WITH with no writes, locks or unsafe functions.

G-03

Bounded execution

Every query carries a statement timeout and a row limit, configured per deployment.

G-04

Controlled egress

An explicit policy decides whether metadata or results may reach an external model.

G-05

No silent changes

Schema changes are proposed as DDL with rationale and evidence. They are never applied automatically.

G-06

Honest provenance

Verified facts and inferred knowledge are always labelled differently, in every interface.

§7 Model providers
Anthropic Claude
Hosted. Default model claude-opus-5-5, with server-side refusal fallback.
Ollama
Local. Any model you run inside your network; nothing leaves it.
Custom
Any provider that implements the LLMProvider interface.

Roadmap

PostgreSQL first, done properly.

Now · v0.1
  • PostgreSQL introspection and schema graph
  • Validated natural-language queries
  • Deterministic and use-case advisors
  • CLI, SDK, server and web app
Next
  • Performance advisor from EXPLAIN and pg_stat_statements
  • Metadata store with snapshot history and diffs
  • Saved questions and shared insights
Later
  • MySQL and SQLite adapters
  • VS Code extension
  • Team permissions and audit trail

Epilogue

Not merely chat with your database.

The opportunity is helping developers understand what their database means, what it is missing, and how to use it to make better decisions.

Precision in the product. Fluidity in the identity. Clarity in every decision.