Grounded compute
For counts, totals and averages, the model writes a one-line query and JDogo computes the answer in your process. Every answer comes with the rows it used and a second, independent computation of the same result.
Why
Models reading rows miscount. In our recorded runs, models answering counting and totals questions by reading the rows got 74 of 150 right; writing a query that JDogo ran, they got 150 of 150. See Questions about large tables.
- The model plans. It reads a short schema card instead of the table and writes an expression such as
sum(fee) where status = "COMPLETED". - JDogo computes. The expression is parsed and evaluated by the SDK. It can only filter and aggregate; it cannot run code.
- You can see which rows.
matched_rowsis the number of rows that passed the filter, androw_refsnames up to 1,000 of them. - You get a check.
checkrecomputes the answer with a second, simpler evaluator that shares only the parser. It reportspassed,mismatch, ornot checkedwhen the query goes beyond what it handles (nested fields, lists, group-by, mixed types).
Example: a 2,000-row ledger
Five questions over examples/data/ledger.json, 2,000 generated orders and payments (seed 42). The expressions are the kind a model writes; this page runs them directly, and scripts/generate_grounded_compute_docs.py rebuilds it from the data.
| Question and expression | Answer | Rows used and check |
|---|---|---|
How many completed transactions are there?count where status = "COMPLETED" |
1,518 | 1,518 rows, starting ORD-1001, ORD-1003, ORD-1004, … Check: passed |
What is the total fee collected from completed credit card transactions?sum(fee) where status = "COMPLETED" and method = "credit_card" |
8,896.69 | 374 rows, starting ORD-1004, ORD-1006, ORD-1008, … Check: passed |
What is the average transaction amount for USD orders?avg(amount) where currency = "USD" and type = "ORDER" |
897.63 | 420 rows, starting ORD-1005, ORD-1009, ORD-1017, … Check: passed |
How many distinct customers had pending transactions?count distinct(customer_id) where status = "PENDING" |
177 | 296 rows, starting ORD-1002, ORD-1021, ORD-1022, … Check: passed |
What is the maximum transaction amount among crypto payments?max(amount) where method = "crypto" |
1,848.61 | 506 rows, starting ORD-1002, ORD-1016, ORD-1018, … Check: passed |
In code
ask() returns the answer with everything needed to audit it:
from jdogo import ask
result = ask("How many completed transactions are there?", ledger, llm=call_model)
print(result.answer) # 1518
print(result.expression) # count where status = "COMPLETED"
print(result.matched_rows) # 1518
print(result.row_refs[:5]) # ["ORD-1001", "ORD-1003", "ORD-1004", ...]
print(result.check) # "passed"import { ask } from "jdogo";
const result = await ask("How many completed transactions are there?", ledger, callModel);
console.log(result.answer); // 1518
console.log(result.expression); // count where status = "COMPLETED"
console.log(result.matchedRows); // 1518
console.log(result.rowRefs); // ["ORD-1001", "ORD-1003", "ORD-1004", ...]
console.log(result.check); // "passed"JDogoAI.AskResult result = JDogoAI.ask(
"How many completed transactions are there?",
ledger,
prompt -> callModel(prompt)
);
System.out.println(result.answer()); // 1518.0
System.out.println(result.expression()); // count where status = "COMPLETED"
System.out.println(result.matchedRows()); // 1518
System.out.println(result.rowRefs()); // ["ORD-1001", "ORD-1003", "ORD-1004", ...]
System.out.println(result.check()); // "passed"Which rows are named
- ID column. The first column named
id,*_idor*Idwhose values are all present and unique. - Otherwise, row positions. Zero-based indexes, for example
[0, 2], including when an ID column has duplicates. - At most 1,000. Beyond that,
row_refs_cappedis true;matched_rowsis always the full count. - Only when asked for.
ask()always includes them. For a direct call, passwith_refs=True({ withRefs: true }in TypeScript,runCompute(expr, data, true)in Java); without it, compute skips the extra pass over the data.