Query Until Verified
Write a SQL query for a business question, run it on a read-only connection, and refine it until row counts, totals, and sanity checks reconcile.
Copy the Query Until Verified loop
Stops when the query result passes every sanity check and reconciles with a known reference number, or after 6 iterations. Edit the settings block, then paste the whole prompt into your agent.
You are running the "Query Until Verified" loop. Settings (edit before running): - Question: <for example, monthly active customers by plan for the last 6 months> - Connection: read-only role on the analytics replica - Reference number to reconcile with: <for example, last month's active customers on the billing dashboard> - Max iterations: 6 Goal: a query whose result answers the question and passes every check below. Before the loop: list the tables you plan to use, their primary keys, and the join keys between them. Confirm the time zone of timestamp columns. Each iteration: 1. Write or revise the query. Use explicit joins and comment each filter. 2. Run these checks as separate queries, each with a LIMIT or aggregate: - Row count before and after each join (unexpected growth means a fan-out). - Duplicate check on the result's grain. - Null counts in key and grouping columns. - Min and max dates actually covered. 3. Compare the matching slice of the result with the reference number. Explain any difference. 4. Log: iteration, what changed, check results. Stop when: - All checks pass and the result reconciles with the reference (or the difference is fully explained). Success. - You reach the max iteration count. Rules: - Read-only. Run SELECT statements only. No INSERT, UPDATE, DELETE, DDL, or temporary tables on shared databases. - Always use LIMIT or aggregates when exploring. Never select entire large tables. - Do not output personal data (emails, names, addresses). Aggregate or count instead. Final report: the final query, the check results, the reconciliation, and assumptions a reader should know.
When this loop fits
- You need a number for a report and want more than a query that merely runs without errors.
- A dashboard metric looks off and you want to rebuild it from raw tables.
- You are exploring an unfamiliar schema and need the joins checked before trusting the result.
What happens on each pass
The agent repeats these steps until the stop condition holds or it runs out of iterations.
- Learn the schema. Inspect the relevant tables, keys, and column types before writing SQL.
- Draft the query. Write the query with explicit joins, filters, and time zone handling.
- Run sanity checks. Check row counts at each join, duplicates, nulls in key columns, and the date range covered.
- Reconcile. Compare the result with a reference number such as a dashboard value, invoice total, or count of raw events.
- Refine. Fix the query and repeat until every check passes.
MCP servers for this loop
The 6 strongest of 1079 matching servers, ranked by how closely they fit and then by trust score.
- 77Trust score 77 of 100, Good
Token-efficient database MCP server for PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite
RegistryLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 25 days ago. - 72Trust score 72 of 100, Good
Mnemosyne
by 28naem-del · TypeScript
Evidence-tracked local memory MCP server: one SQLite file; corrections retire dependent memories.
RegistryLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: C. 65/100 for listing completeness. Lost points: no listed tools, short summary.Maintenance: A. Last commit or release 11 days ago.
71Trust score 71 of 100, GoodSynaBun
by danilokhury · JavaScript
Persistent memory MCP server for Claude Code, Codex and OpenCode, stored locally in SQLite
RegistryLicenseQualityMaintenanceLicense: A. Apache-2.0 is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 16 days ago.- 71Trust score 71 of 100, Good
faostat-mcp-server
by cyanheads · TypeScript
UN FAOSTAT global food & agriculture statistics over a local SQLite mirror, via MCP.
RegistryRemoteLicenseQualityMaintenanceLicense: A. Apache-2.0 is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 10 days ago. - 70Trust score 70 of 100, Good
Database MCP server for MySQL, MariaDB, PostgreSQL & SQLite with PII redaction and write-prevention
RegistryLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 21 days ago. - 70Trust score 70 of 100, Good
LLMSlim memory
by thanatos9404 · Python
Long-term memory and context fitting for agents, with no LLM in the loop. Local SQLite.
RegistryLicenseQualityMaintenanceLicense: A. MIT is a permissive open source license.Quality: Not graded. No README or tool list has been captured yet.Maintenance: A. Last commit or release 9 days ago.
How to run this loop
- Connect the tools. Install a server the loop can use, for example DBHub, or rely on your agent's built-in terminal and file access.
- Edit the settings block. Replace the example commands, targets, and limits with your project's own. Keep the iteration cap low on the first run.
- Paste it into an agent session. Start a fresh session in Claude Code, Cursor, or VS Code agent mode, in the repository root, and paste the prompt.
- Review before you merge. Read the final report and the diff. The loop leaves its work for you to review rather than shipping it.
Query Until Verified questions
When does the Query Until Verified loop stop?
It stops as soon as the query result passes every sanity check and reconciles with a known reference number. It also stops after 6 iterations by default, or earlier when the prompt's own stop rules say it is stuck, and then reports what changed and what is left. Change the cap in the settings block at the top of the prompt.
How do I make sure the agent cannot change my database?
Connect the database MCP server with a role that only has SELECT privileges, ideally on a replica. Several database servers also have a read-only mode. The prompt forbids writes too, but database permissions are the guarantee that matters.
What is a join fan-out and why does the loop check for it?
A fan-out happens when a join matches one row to many, silently multiplying counts and sums. It is the most common reason a query runs cleanly but returns the wrong number, so the loop compares row counts before and after every join.