Products · LLM Extraction V1

Extraction with Claude

Claude turns a document into structured data, with a confidence score and evidence for every field.

Version 1 · One Claude call per documentDesigned, not builtModule 4 of 15

ProductRequirement EPICSections

Requirement EPIC

Epic
MVP1 · E3 · Extraction with Claude
Goal
accurate structured data, with confidence and evidence for every field.
Stories in this module
10

EXTRACTION-V1-E3-01 Extraction job lifecycle

  • AC1A job moves through queued → processing → extracted | failed. Each change is stored and visible through GET /api/extraction/v1/jobs/{jobId}.
  • AC2Temporary failures (rate limit, timeout, overload) retry up to 2 times with backoff; after that the job is failed with a user-friendly message and a "Retry" button.
  • AC3Jobs are idempotent: calling extract twice for the same document doesn't create two jobs or bill twice.

EXTRACTION-V1-E3-02 Claude extraction call

  • AC1The document (PDF or image) is sent to Claude as a document or image input along with the versioned prompt prompts/extract-invoice/v1.md.
  • AC2The output is forced into the invoice v1 schema (PRD §9) with a tool/JSON schema. Every field includes value, confidence, source_page and source_quote.
  • AC3The model ID and prompt version are read from configuration and saved on the job.
  • AC4The response is validated with zod. A schema failure triggers one repair attempt and then fails the job; invalid JSON is never stored.
  • AC5Scanned PDFs and photos are in scope. Before extraction, the job reads each page's text: the PDF's text layer, or OCR by Claude when there is none or the file is an image. If no text is found, the job fails with no_text_found and the person sees "No text found" (Nikhil's decision on #34).
  • AC6The default model is claude-opus-5-5 (Nikhil's decision on #34).
  • AC7**Demo budget (Nikhil's decision on PR #87):** each calendar month (UTC), jobs use claude-opus-5-5 until $5 of Opus cost is used, then claude-haiku-5-5 until $5 of Haiku cost is used. When both are used, a new job is refused with 503 demo_budget_reached and Retry-After set to the start of next month. Spend is the sum of cost_usd on the month's jobs, per model and **per app**, found from each job's reference prefix: every app has its own budget of this size (Nikhil's decision, 21 Nov 2026), and AutoRep counts its own (AUTOREP-V1-E6-02). The hard backstop is outside the code: prepaid API credit with auto-reload off and a $20 monthly spend limit on the Anthropic workspace (DocFlow's $10 and AutoRep's $10), so the bill can never exceed $20. Moving the budget into one platform component is CORE-V2-E15-02.
  • AC8The eval report covers both models. If Haiku scores below a threshold, it still runs: confidence routing sends more fields to human review, and the Costs page says so.

Evals: EXT-1 schema validity, EXT-2 header field accuracy, EXT-3 line item F1, EXT-4 hallucination rate, EXT-7 latency, EXT-8 cost (see EVALS.md).

EXTRACTION-V1-E3-03 Rule checks and final confidence

  • AC1The arithmetic, date, currency, required-field and source-quote checks (PRD §10) run on every extraction.
  • AC2Final confidence = the lower of model confidence and rule result (a failed check sets 0.3). Fields under the threshold (default 0.85) or failing a check are marked flagged.
  • AC3Each flagged field stores the reason ("Total ≠ subtotal + tax", "Quote not found in document").
  • AC4Unit tests cover every rule check, including rounding and missing-tax cases.
  • AC5The source-quote check runs for scans and photos too, against the OCR text (decision on #35).

Evals: EXT-5 routing recall, EXT-6 flag rate.

EXTRACTION-V1-E3-04 Extraction page

  • AC1While processing, the page shows status steps and polls every 2 seconds, without a full-page reload.
  • AC2When done, the document preview (rendered PDF page or image, Upload's FilePreview component, decided on #36) is on the left and the fields on the right, with confidence badges (green ≥ 0.85, amber 0.6–0.85, red < 0.6) and flagged fields highlighted.
  • AC3Tapping a field shows its source quote and page. On desktop, the preview jumps to that page.
  • AC4A "Review N flagged fields" button goes to E4. If nothing is flagged, "Continue to results" goes to E5.
  • AC5The page says which model read the document. When it was Claude Haiku 5.5, it shows: "This month's demo budget for Claude Opus 5.5 is used, so this document was read by Claude Haiku 5.5, a faster, lower-cost model. More fields may be flagged for your review." When both budgets are used, the upload step shows: "Demo capacity for this month is used up. Extraction is back on <date>." (Nikhil's decision on PR #87).

EXTRACTION-V1-E3-05 Cost and latency logging

  • AC1Each job stores tokens in and out, estimated cost in USD and duration.
  • AC2An admin-only page /admin/jobs shows the last 100 jobs with these numbers and the failure rate.
  • AC3The admin page also shows this month's spend per model against its $5 budget (EXTRACTION-V1-E3-02 AC7).

EXTRACTION-V1-E3-06 Ask questions about my documents (RAG)

As a user, I want to ask a question in plain language across my processed invoices, such as "How much did I pay Acme Supplies in October?", and get an answer that shows the invoices it came from.

  • AC1When an extraction finishes, the document's page text (extraction.page_texts) is split into passages, turned into embeddings and added to the owner's own index. Deleting a document or the account deletes its passages.
  • AC2A question retrieves the most relevant passages **only from the caller's own documents** (the owner filter is part of the search itself, never applied afterwards), and Claude answers using only those passages.
  • AC3Every statement in the answer cites its document, page and quote. Each quote is checked against the retrieved text, as the extraction quote check does; a statement whose quote is not found is removed. If nothing relevant is found, the answer says so instead of guessing.
  • AC4The question box can be limited to chosen documents. The answer shows its citations as links that open the document at the cited page, using Upload's FilePreview.
  • AC5Evals RAG-1 to RAG-4 (docs/services/extraction/v1/EVALS.md) meet their thresholds on the synthetic dataset before release. Model, prompt version, tokens, cost and time are recorded per question, like extraction jobs.
  • AC6Asking counts towards the limit of 10 requests a minute that change something; agents can ask through the MCP tool extraction.askDocuments, within the same limits.

Evals: RAG-1 retrieval recall, RAG-2 faithfulness, RAG-3 refusal on unanswerable questions, RAG-4 latency and cost (see EVALS.md).

EXTRACTION-V1-E3-07 Jobs table for the admin as a UI component (`ui-extraction`)

**Status: built (#165), 23 Nov 2026,** in ui-extraction 0.3.0, against a stand-in client until the service is built; every state is live on the module's UI Components section. Added 22 Nov 2026 (Nikhil), when CORE-V1-E0-19 AC5 marked this component "Designed, not built yet".

As the owner, I want the admin's jobs table built as Extraction's UI component, so I can watch cost, speed and failures in any app.

  • AC1JobsTable is built as designed in docs/services/extraction/v1/UI-COMPONENTS.md: the last jobs with model, prompt version, pages, tokens, cost, time and outcome, with the failure rate, average cost and slowest time on top. To anyone who is not an admin it shows "Not found", as the API answers.
  • AC2Each component is built in packages/ui-extraction on @01scale/ui-core, calls only its own service's API through the package's client, and has every state its design lists (loading, empty, failed and each data state).
  • AC3Each component is shown live, in each of its states, on its module's UI Components section, replacing "Designed, not built yet" (CORE-V1-E0-19 AC5).
  • AC4Keyboard reachable, visible focus, labelled controls, WCAG AA contrast, usable at 320 pixels wide, in light and dark mode.

EXTRACTION-V1-E3-08 Hold a job's fields for the app that started it

**Status: designed (#177), 23 Nov 2026 (Nikhil's decision; docs/services/shared/v1/DECISIONS.md).**

As an app (DocFlow), I want to hold an extraction's results until my own condition is met, so a person cannot read them around my paywall, while Extraction stays app-agnostic.

  • AC1POST /api/extraction/v1/jobs accepts hold: true only with a delegated token; the acting app in its act claim becomes the job's held_by. With a person's own token or an API key it answers 422 hold_requires_app.
  • AC2While a job is held, GET /jobs/{jobId}/fields with the owner's own token or API key returns only the flagged fields, whatever flagged says, with held: true and fields_hidden; the holding app, with a delegated token naming it in act, gets every field. GET /jobs/{jobId} shows held_by and released_at.
  • AC3POST /jobs/{jobId}/release lets only the holder release the job (403 not_holder for anyone else, 409 not_held for a job never held); it is safe to repeat, and records job.released in the audit log. After release, the owner reads every field.
  • AC4Extraction never learns why a job is held. Tests cover owner, holder, other app and released reads.

EXTRACTION-V1-E3-09 A free daily quota for jobs a person starts

**Status: designed (#181), 23 Nov 2026 (Nikhil's decision; docs/services/shared/v1/DECISIONS.md).**

As the owner, I want a person who calls Extraction directly, not through an app, to get a small free allowance, so the hold on an app's results (EXTRACTION-V1-E3-08) cannot be sidestepped for free by running their own job, and our Claude spend stays capped, while Extraction stays usable by people and their agents.

  • AC1A job started with a person's own token or API key counts toward their free daily quota: 3 a day by default (EXTRACTION_DIRECT_DAILY_QUOTA), reset at 00:00 UTC. A job an app starts with a delegated token counts toward the app, not the person. Returning a job that is already running, and a job that fails for a temporary reason, do not count.
  • AC2Past the quota, POST /jobs answers 429 quota_exceeded, with Retry-After until 00:00 UTC and a message saying how many were used and when more open. The gateway's rate limit (10 changes a minute) still applies on top.
  • AC3GET /api/extraction/v1/usage shows today's direct_jobs_used, direct_jobs_limit, resets_at and plan (free), and is an MCP tool (getUsage), so an agent can check before it starts a job.
  • AC4The quota is counted from started_by and created_at when a job is created, so retrying or reconnecting cannot dodge it. Tests cover a person's own jobs, an app's jobs for them, a temporary failure, and the reset.
  • AC5Until Extraction has a paid plan (01SCALE-V1-E0-28 AC6), the quota is the limit.

EXTRACTION-V1-E3-10 Spike: LLM extraction options (AWS, Claude, Microsoft)

As the owner, I want to compare the ways to extract structured data from invoices before building on one, so the choice of Claude for Extraction is measured, not assumed (Nikhil, PR #189).

  • AC1A timeboxed spike (8 days at most) runs the same synthetic invoice set (evals/datasets/invoices/dev, no real user documents) through three options: **AWS** (Textract AnalyzeExpense, and a Claude model on Bedrock), **Claude** through the Anthropic API with the structured output planned in EXTRACTION-V1-E3-02, and **Microsoft** (Azure AI Document Intelligence, prebuilt invoice model).
  • AC2It compares field accuracy against ground truth, per-field confidence, cost per document, latency, data-handling terms (retention, training, region) and how each fits the Extraction contract, using the metrics in docs/services/extraction/v1/EVALS.md.
  • AC3The result is a decision record in docs/services/shared/v1/DECISIONS.md: options, measurements, recommendation and what would change it. Nikhil makes the decision; EXTRACTION-V1-E3-02 is built on it.
  • AC4Spike code stays out of the services (a spikes/ folder or a branch), and no keys or documents are committed.