Retrieve tabular evidence without losing row keys, column units, revision dates or the calculation needed for an answer.
Table retrieval: keep numeric cells attached to their labels
Treat a cell as a qualified fact
The value 47 has no useful meaning alone. A searchable fact needs table ID, revision, row key, column name, unit, effective period and access label. Store a compact row rendering for discovery, but preserve typed cells for comparison and arithmetic. A question about the West queue's 47-hour target must not match a North queue row or a 47-day retention policy. Extraction provenance should point back to the original table location.
Separate discovery from computation
Use lexical or semantic search to locate a candidate table, then execute an approved operation over its typed rows. Do not derive a total by reading the top few text snippets; omitted rows silently bias the result. Exact row and column filters should run before aggregation. If the requested metric is not defined, ask for the metric rather than inventing a sum. Record the row IDs used so the answer can be audited after a table revision.
Handle headers and units
Merged headings, repeated page headers and blank cells need explicit parsing rules. A blank value can mean unknown, not zero. A percentage column cannot be summed like a count, and a currency column cannot be combined across currencies without a declared conversion rule. If a table changes from hours to minutes in a new revision, the retrieval layer must not silently mix both. Index swaps should move the searchable row text and typed table together.
Test answer coverage
Judged queries should include an exact cell lookup, a filter plus sum, a percentage with denominator, a missing cell and a superseded revision. Evaluate table discovery separately from calculation correctness. A system that retrieves the right table but adds the wrong rows still fails. For each calculated answer, retain the operation, selected row keys, table revision and resulting value.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class QueueRow:
region: str
week: int
resolved: int | None
revision: str
def resolved_total(rows: list[QueueRow], region: str, weeks: set[int],
revision: str) -> int:
selected = [row for row in rows if row.region == region
and row.week in weeks and row.revision == revision]
if len(selected) != len(weeks) or any(row.resolved is None for row in selected):
raise ValueError("incomplete table coverage")
if len({row.week for row in selected}) != len(selected):
raise ValueError("duplicate row key")
return sum(row.resolved for row in selected if row.resolved is not None)
queue_rows = [QueueRow("West", 31, 47, "r8"),
QueueRow("West", 32, 29, "r8"),
QueueRow("North", 31, 81, "r8")]
assert resolved_total(queue_rows, "West", {31, 32}, "r8") == 76
try:
resolved_total(queue_rows, "West", {31, 33}, "r8")
except ValueError:
pass
else:
raise AssertionError("missing week was accepted")Performance and operating cost
The baseline scans N rows in O(N) time and stores O(K) selected rows. A typed index on revision, region and week avoids a full scan in a large warehouse; query cost then depends on matching rows and index lookup. Preserve row lineage even if it adds metadata, because a wrong numeric answer is harder to diagnose than a slow lookup.
Common Mistakes
- Embedding isolated numeric cells without their row and column labels.
- Treating blank cells as zero during aggregation.
- Summing a top-k snippet sample instead of the full filtered table.
- Combining rows from different revisions or units.
Validation drill
Build a 29-row queue table with two revisions and three regions. Answer 12 cell questions and eight aggregate questions. Make two cells blank and one row duplicated; require explicit errors for both cases.
Read next
- Document extraction: preserve passage provenance through OCR and parsing
- Retrieval query routing: preserve exact constraints before search
- Claim-level citations: verify each answer against its passage
- Schema compatibility and consumer rollout
