
Use case / Data and SQL agents
Read the query the agent actually ran.
A data agent turns a question into SQL and then sounds sure about the result. Trace the schema it read, the query it wrote and the rows it got back, and a wrong join is easy to spot.
- Queries
- Recorded
- Rows
- Counted
- Retries
- Visible
Instrument it
Store the SQL exactly as it ran.
Wrap the schema read, the query and the explanation, and a wrong number points to the query that made it.
$ npm install tracify-sdk
import { span, traceAgent } from "tracify-sdk";
export const ask = traceAgent(async (question: string) => {
const sql = await span("write-sql", () => writeSql(question), { type: "llm", input: question });
const rows = await span("run-query", () => db.query(sql), { type: "tool", input: sql });
return span("explain", () => explain(question, rows), { type: "llm" });
}, { environment: "production" });Query record
The query behind the number.
The question is the root of the trace, so every query has a reason.
See which tables and columns the agent looked at before writing.
The SQL is stored exactly as it ran, with timing.
Row counts make a bad join obvious next to the question.
The explanation links back to the query that produced it.
- 01ok
Question received
“What was revenue by region last quarter?”
- 02ok
Schema read
Four tables, nine columns used.
- 03ok
Query written
Joins orders to customers and regions.
- 04doubled
Join doubled the rows
Rows returned: 2x the order count.
- 05ok
Answer explained
The summary quotes the inflated total.
What you get
What Tracify watches.
Generated query
01Recorded on every run, so it can be searched, compared and alerted on.
Rows returned
02Recorded on every run, so it can be searched, compared and alerted on.
Query time
03Recorded on every run, so it can be searched, compared and alerted on.
Retry count
04Recorded on every run, so it can be searched, compared and alerted on.

The failure to catch
A confident number built on a join that doubled every row.
Trace how a data agent turns a question into SQL, runs it and explains the result, so a wrong join is visible before anyone trusts the number.
