Skip to content
TuffTasks, docs and chat for teams and AI agents

Interactive Answers

Extraction Grid

An agent reading a stack of invoices into a sheet — values stream in with confidence bars, weak ones flagged for review, each cell opening its source passage, editable like a spreadsheet.

1 variantMIT

Preview

Invoice extraction

8 invoices · 4 fields

0/32read

Reading 8 documents… 0 of 32 values so far.

DocumentVendorAmountDue dateTerms
northwind-inv-2291.pdfInvoice · 2 pp
halcyon-cloud-oct.pdfInvoice · 4 pp
Meridian-Legal-Q3.pdfInvoice · 6 pp
scan_0042.pdfScanned · 1 p
orbital-data-1107.pdfInvoice · 1 p
Pinecrest-Catering.pdfInvoice · 1 p
INV_88412_Brightline.pdfInvoice · 1 p
vantage-media-inv.pdfInvoice · 3 pp

Extracting 4 fields…

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest add https://tuffui.com/r/extraction-grid.json

Usage

Pass your own data and wire the callbacks to your agent runtime.

import { ExtractionGrid } from "@/components/ui/extraction-grid";

// Rendered by the agent after the user drops a stack of invoices into the chat.
export function InvoiceExtraction({ files, results, running }: Props) {
  return (
    <ExtractionGrid
      status={running ? "extracting" : "done"}
      fields={[
        { key: "vendor", label: "Vendor" },
        { key: "amount", label: "Amount", align: "right", numeric: true },
        { key: "due", label: "Due date", numeric: true },
        { key: "terms", label: "Terms" },
      ]}
      documents={files.map((file) => ({
        id: file.id,
        name: file.name, // "northwind-inv-2291.pdf"
        meta: `Invoice · ${file.pages} pp`,
        // Keys appear as the model streams them; missing ones show as placeholders.
        cells: results[file.id] ?? {},
      }))}
      onCellConfirm={(cell) => markReviewed(cell)}
      onCellEdit={(cell, value) => saveCorrection(cell, value)}
      onExport={(csv) => download("invoices.csv", csv)}
    />
  );
}

Props

PropTypeDefaultDescription
documents*ExtractionDocument[]—One row per file. `cells` maps a field key to its extracted value; keys that are missing are still being read.
fields*ExtractionField[]—The columns. `numeric` sets amounts and dates in tabular figures, `align` right-aligns them, `minWidth` is how narrow a column gets before the grid scrolls sideways.
status"extracting" | "done""done"Extracting shows unread cells as pulsing placeholders, counts values read in the header and holds the export.
reviewThresholdnumber0.7Confidence under which a cell is tinted and labelled "Review" until someone confirms or edits it.
openCellExtractionCellRef | null—Controlled cell whose source popover is open. Omit to let clicks and Enter open it.
onOpenCellChange(cell: ExtractionCellRef | null) => void—Called when a cell's popover opens, moves with the arrow keys or closes.
onCellConfirm(cell: ExtractionCellRef) => void—Shows Confirm in the popover. Enter on an open flagged cell confirms too. Set `confirmed` on the cell in response.
onCellEdit(cell: ExtractionCellRef, value: string) => void—Makes cells editable: double-click, F2 or start typing. Enter saves and moves down, Tab moves right, Esc cancels. Set the new value and `edited` in response.
onExport(csv: string) => void—Shows the primary "Export CSV" button. Gets the whole grid as CSV text.
summaryReactNode | ((stats: ExtractionStats) => ReactNode)—Agent text above the grid. Defaults to a line built from the live counts: values read, then how many are under the threshold.
iconIconScanPhosphor icon in the header tile.
titleReactNode"Extraction"Header title, also the grid's accessible name.
subtitleReactNode"8 documents · 4 fields"Secondary line under the title.
documentLabelstring"Document"Heading of the first column and the CSV.
introbooleantrueRows slide in, values blur in and confidence bars grow as they arrive. Skipped with reduced motion.
classNamestring—Extra classes for the root element.
type ExtractionField = {
  key: string;
  label: string;          // "Due date"
  align?: "left" | "right";
  numeric?: boolean;      // tabular figures for amounts and dates
  minWidth?: number;      // px, default 116
};

type ExtractionDocument = {
  id: string;
  name: string;           // "northwind-inv-2291.pdf"
  meta?: string;          // "Invoice · 2 pp"
  cells: Partial<Record<string, ExtractedCell>>;
};

type ExtractedCell = {
  value: string;          // "$12,480.00"
  confidence: number;     // 0–1
  source?: {
    text: string;         // the passage it was read from
    highlight?: string;   // part of text to mark, defaults to value
    page?: number;
  };
  confirmed?: boolean;    // checked by a person
  edited?: boolean;       // typed by a person
};

type ExtractionCellRef = { docId: string; field: string };

type ExtractionStats = { documents: number; total: number; filled: number; review: number };

// Also exported: needsReview(cell, threshold), extractionToCsv(documents, fields)