Compare experiment results with SQL
Tutorial 10 of 15 · Run a research project. Follow the sequence or bring your own equivalent inputs.
Keep an experiment log as a CSV in MassifyAI's knowledge base, then ask your agent to compare results without loading the whole file into the conversation. In this example, you will choose which personal news intelligence approach deserves another experiment, considering quality, response time, cost, and missing results.
Continue the research storyline: use the “Example: News briefing protocol” and task from Tutorial 9 with the same research brief and synthetic CSV. Keep the links returned here for the final research handoff.
The workflow also fits model evaluations, computational research results, and biology or chemistry evidence tables. Store the table alongside the protocol and findings so another person or agent can understand both the numbers and what they mean.
This is recursive self-improvement for the workspace in a research workflow: the protocol guides experiments, SQL helps evaluate the evidence, reviewed findings improve the next experiment plan, and the next session starts from that accumulated knowledge. When a review reveals a reusable evaluation check, you can also propose an improvement to the project's research skill or agent profile.
Availability: beta table tools. Ask your agent to check for the four tools below; release and project availability may differ. The example uses synthetic data so you can inspect the queries, exclusions and result tables before applying the workflow to your own experiments.
Before you start
Connect MassifyAI to Claude Code or Codex with Connect with one prompt. Ask your agent to confirm your organization and project with whoami. You need permission to read the CSV; creating a table needs Editor or Admin access in the project. Updates follow the document's editing and approval rules.
First pass: use steps 1–5, skip the optional table edit in step 6, then save your finding in step 7. Paste the prompt blocks into your agent chat; the SQL blocks show what the agent runs through MCP, so you do not need a SQL editor. Keep the same chat, or give a new chat your table and protocol links. If starting here, use the CSV below; a real dataset or paid compute is not required.
Ask your agent whether it has these tools:
knowledge_create_table: create a CSV table.knowledge_query_table: query a CSV using read-only SQL.knowledge_append_table_rows: add results without rewriting the file.knowledge_update_table_rows: update existing rows by a key column.
If the tools are missing, refresh the connection and follow Troubleshooting. Do not substitute a similarly named tool or assume a console SQL editor exists. This workflow uses the coding agent and MCP tools; the CSV itself remains a knowledge base document.
Start with the research workflow
Load the curated Data & Spreadsheet Analyst agent profile and scientific-research-with-massifyai skill before comparing results. The steps below expose the queries and expected answers so you can inspect the method and reproduce it.
1. Add the sample experiment log
Download experiment-runs.csv. All nine rows are synthetic examples, not real benchmark results.
In the console, open knowledge base → Add document → Upload a file and upload the CSV into your current project. File it under a folder such as Research/Experiments. If the upload lands at the root, move it into that folder afterward.
Alternatively, attach the downloaded file to the agent chat (or give its local path) and say:
The agent can read the local CSV and use knowledge_create_table with its header as columns and its rows as objects. It must report the actual returned document ID. The same CSV can be queried whether uploaded or created through the tool.
The example columns are:
| Column | Meaning |
|---|---|
run_id | A stable identifier, unique for each run |
experiment | baseline, rag, or rag-rerank |
dataset_version | The evaluation set used; compare like with like |
seed | The run's seed |
status | Whether the run completed or failed |
quality_score | A fictional score from 0 to 1; higher is better |
latency_ms | Milliseconds per request; lower is better |
cost_usd_per_request | US dollars per request; lower is better |
run_date, code_revision | When it ran and which implementation it used |
For a real project, save a companion protocol defining the score, dataset, evaluator, units, and evaluation conditions. The sample's revision strings are illustrative. In real records, use actual code revisions and links to the underlying evidence.
2. Inspect the table before drawing conclusions
The exact call is knowledge_query_table with the document's real id and this SQL:
SELECT * FROM t ORDER BY run_id LIMIT 3;
The query sees this CSV as a table called t. It does not need a database connection string or a server filesystem path. The response includes the document version, source table columns/types, result rows, and nextOffset when more result rows remain.
Filled numeric columns are inferred as numbers; ISO date columns as dates; other columns as text. Empty CSV cells become SQL NULL. Values such as 007 or long identifiers are kept as text by the implementation's inference rules. Inspect the returned types, especially when an instrument export mixes units and numbers in one column.
3. Check incomplete runs and mixed datasets
Ask:
SELECT dataset_version, status, COUNT(*) AS runs,
COUNT(quality_score) AS scored_runs
FROM t
GROUP BY dataset_version, status
ORDER BY dataset_version, status;
Expected result:
| Dataset | Status | Runs | Scored runs |
|---|---|---|---|
| support-v1 | completed | 7 | 6 |
| support-v1 | failed | 1 | 0 |
| support-v2 | completed | 1 | 1 |
There are nine rows, but only six completed, scored runs belong to support-v1. One run failed, one completed without a quality score, and another used a different dataset version. Empty scores are missing observations, not zero-quality results. Report these exclusions alongside any comparison.
4. Compare like-for-like experiments
SELECT experiment, COUNT(*) AS measured_runs,
ROUND(AVG(quality_score), 3) AS mean_quality,
ROUND(AVG(latency_ms), 0) AS mean_latency_ms,
ROUND(AVG(cost_usd_per_request), 3) AS mean_cost_usd
FROM t
WHERE dataset_version = 'support-v1'
AND status = 'completed'
AND quality_score IS NOT NULL
AND latency_ms IS NOT NULL
AND cost_usd_per_request IS NOT NULL
GROUP BY experiment
ORDER BY mean_quality DESC, experiment;
Expected result:
| Approach | Measured runs | Mean quality | Mean latency (ms) | Mean cost (USD/request) |
|---|---|---|---|---|
| rag-rerank | 2 | 0.87 | 2,150 | 0.026 |
| rag | 2 | 0.82 | 1,450 | 0.018 |
| baseline | 2 | 0.73 | 1,050 | 0.010 |
Reranking has the highest mean quality here, but also the highest latency and cost. This is a description of a tiny synthetic sample, not evidence that one method is generally superior. In real research, report uncertainty and inspect the missing/failed runs before making a promotion decision.
5. Choose the next experiment under explicit constraints
Suppose your prototype needs average latency at most 1,600 ms and cost at most $0.020 per request. These are tutorial assumptions, not MassifyAI limits.
WITH comparable AS (
SELECT experiment, COUNT(*) AS measured_runs,
AVG(quality_score) AS mean_quality,
AVG(latency_ms) AS mean_latency_ms,
AVG(cost_usd_per_request) AS mean_cost_usd
FROM t
WHERE dataset_version = 'support-v1'
AND status = 'completed'
AND quality_score IS NOT NULL
AND latency_ms IS NOT NULL
AND cost_usd_per_request IS NOT NULL
GROUP BY experiment
), baseline AS (
SELECT mean_quality FROM comparable WHERE experiment = 'baseline'
)
SELECT c.experiment, c.measured_runs,
ROUND(c.mean_quality, 3) AS mean_quality,
ROUND(c.mean_quality - b.mean_quality, 3) AS gain_over_baseline,
ROUND(c.mean_latency_ms, 0) AS mean_latency_ms,
ROUND(c.mean_cost_usd, 3) AS mean_cost_usd
FROM comparable c CROSS JOIN baseline b
WHERE c.mean_latency_ms <= 1600 AND c.mean_cost_usd <= 0.020
ORDER BY c.mean_quality DESC, c.experiment;
The first result should be rag: quality 0.82, an absolute improvement of 0.09 over baseline, latency 1,450 ms, and cost $0.018/request. The baseline also fits the constraints. Reranking does not fit them in this sample.
A useful answer would say:
RAG is the strongest candidate for another experiment under these example constraints. Its two measured runs improve mean quality by 0.09 over baseline. Investigate the failed RAG run and missing score, then repeat the comparison on an agreed evaluation set. Two measured runs per approach do not establish a reliable improvement.
The WITH expressions and join above all derive from the same CSV. This does not imply joins across separate knowledge base documents.
6. Optional: add results without replacing the whole CSV
Before changing the table, retain the comparison above as a snapshot: document ID, version, exact SQL, returned result rows and exclusions. Steps 3–5 describe the original nine-row sample. After the append below, re-running them includes r010: there are ten total rows and seven eligible measurements, so the original six-row finding must keep its original version and results.
When another result is available, ask the agent to use knowledge_append_table_rows. Example tool arguments, after substituting the actual document ID:
{
"id": "<document-id>",
"rows": [{
"run_id": "r010",
"experiment": "rag",
"dataset_version": "support-v1",
"seed": 5,
"status": "completed",
"quality_score": 0.80,
"latency_ms": 1480,
"cost_usd_per_request": 0.018,
"run_date": "2026-10-24",
"code_revision": "abc102"
}]
}
This is another synthetic example row. The tool sends only new rows, and applies changes under the document lock; simultaneous direct appends do not replace each other's table content. Check the response for an applied version or a proposal awaiting approval before claiming the row is present.
After a timeout or lost response, query before retrying an append:
SELECT run_id, status, quality_score
FROM t
WHERE run_id = 'r010'
ORDER BY run_id;
An append has no retry key in this interface and does not enforce uniqueness of run_id. Blindly retrying can duplicate the result. Also inspect any pending proposal from the first attempt; a row absent from the current table may still be awaiting approval.
To correct an existing result, use knowledge_update_table_rows with key: "run_id", the values to change, and the baseVersion returned by your latest read. Include the key in each row. Omitted fields remain unchanged on update; an explicit null clears a cell. An unknown key is returned in notFound and is not inserted. A row changed since the base version is returned in conflicts; other non-conflicting rows may have been applied or proposed. Re-read and resolve those rows rather than treating the batch as all-or-nothing.
7. Save the finding and make the next task
After reviewing the results, you can say:
If you followed tutorial 9, link “Example: News briefing protocol” and the existing comparison task. If you started here, have the finding state the example's metric definitions and unknown real-world prerequisites; do not invent a protocol link.
State which snapshot you are saving: the original nine rows have six eligible and three excluded rows; after appending r010, the current table has seven eligible and three excluded rows. Recompute the means for a current-table finding instead of copying the earlier numbers. Preserve a prior finding when later evidence changes it; save a dated successor with a link to the earlier finding.
Then:
A teammate can load the relevant profile, read the finding and protocol, query the same experiment table, and continue the work. If the table changes, retain the original comparison's version and SQL so the reasoning remains traceable. The current query tool queries the current document, not an arbitrary historical version; the stored result snapshot matters too.
You have finished this tutorial when your agent returns a saved finding link (or clearly reports pending review), the table link and version, and one proposed next task. For the unmodified sample, check six eligible rows, three exclusions and RAG's 0.09 quality gain under the example limits. Keep those links for tutorial 11. The next-session section below is for later, after new evidence exists.
8. Close the loop in the next research session
After the follow-up experiment has actual results, append them to the table and ask:
The resulting evidence updates the workspace's next decision. A general lesson—such as always checking failed runs and dataset versions before ranking approaches—can become a reviewed change to a project skill or profile. The next person or agent then uses that improved method. Keep the earlier finding and its evidence traceable when a later finding supersedes it.
This completes the feedback cycle: shared protocol → experiment → evaluation → improved knowledge or method → next experiment. Recording a conversation can supply additional context later; the table, findings, and reviewed procedure already carry the learning between sessions.
Apply the same pattern to biology or chemistry research
Use a CSV with candidate_id, assay_id, batch_id, measurement, unit, evidence_type, source, and review_status. Ask for comparisons within a defined assay, unit, and evidence type. Keep literature summaries and experimental protocols beside the table, and link each finding to its source rows.
For example:
Curated science skills can help collect, interpret, and check the underlying evidence. SQL helps retrieve and compare the recorded results; it does not validate the experimental design or turn a computational prediction into an experimental finding.
SQL reference and recovery
| Behavior | What to do |
|---|---|
One CSV document per query; table name t; DuckDB SQL | Send one SELECT or WITH ... SELECT. No database writes, external file/network reads, or extension installation |
| Column names with spaces or punctuation | Use double quotes, for example "Quality score"; string values use single quotes |
| Result paging | Follow nextOffset using the same SQL and a deterministic ORDER BY. Compare document versions; restart if the source changed |
| Default 100 result rows / 12,000 characters | Narrow the projection first. Tool limits are 1,000 rows and 50,000 characters per response; maximum offset is 10,000 |
Query takes too long or answers busy | Queries have a five-second query budget; narrow/simplify expensive queries and retry busy after other work finishes |
| Table writes | At most 500 rows per call; editable UTF-8 CSV text up to 1,000,000 bytes; named, case-insensitively unique headers; comma-separated format |
| Numbers infer as text | Inspect mixed cells and units; clean deliberately rather than coercing missing/bad values to zero |
not_a_table | Confirm this is a CSV with a header, not an XLSX or a tab/semicolon-delimited export |
query_failed | Check the table name, returned column names/types, and SQL; retain the error instead of inventing results |
A response contains proposal | Say the change is pending; do not report it as saved in the current table |
Use small research ledgers for this workflow, within the editable-table limit. The general file-upload limit is not a promise that every large CSV is fully queryable or editable. Large primary datasets belong in the team's data/compute system; keep the comparison table and evidence links in knowledge base.
Reproduce the example
Use the synthetic CSV and these exact queries: preview, cohort check, comparison, next experiment, retry check. Compare your output with the expected results.