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.

  1. The question is the root of the trace, so every query has a reason.

  2. See which tables and columns the agent looked at before writing.

  3. The SQL is stored exactly as it ran, with timing.

  4. Row counts make a bad join obvious next to the question.

  5. The explanation links back to the query that produced it.

Data and SQL agents1 / 5 steps
  1. 01

    Question received

    “What was revenue by region last quarter?”

    ok
  2. 02

    Schema read

    Four tables, nine columns used.

    ok
  3. 03

    Query written

    Joins orders to customers and regions.

    ok
  4. 04

    Join doubled the rows

    Rows returned: 2x the order count.

    doubled
  5. 05

    Answer explained

    The summary quotes the inflated total.

    ok

What you get

What Tracify watches.

Generated query

01

Recorded on every run, so it can be searched, compared and alerted on.

Rows returned

02

Recorded on every run, so it can be searched, compared and alerted on.

Query time

03

Recorded on every run, so it can be searched, compared and alerted on.

Retry count

04

Recorded 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.