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

DataData ModelSections

Data Model Designed

What the service keeps, how the pieces relate, and what every field means. The SQL is on the Schema tab.

Entities

Job

One attempt to read one file into fields.

Belongs to one user and one file, both by ID only. Has many fields.

extraction.jobs

Field

One value read from the document, with its confidence and evidence.

Belongs to one job; deleted with it.

extraction.fields

Processed event

A platform event already acted on.

Stands alone.

extraction.inbound_events

Prompt

The versioned instructions sent to the model.

Named on each job by prompt_version. A changed prompt is a new version with its own eval report.

(file prompts/extract-invoice/v1.md)

Life of each record

Job
`queued` when asked for → `processing` when the background work starts → `extracted` when its fields are saved, or `failed` after the last retry. A job left `queued` for a minute is picked up by the sweep.
Field
Created with all its job's fields in one step → never changed → deleted only with its job or its owner's account.
The document's content
Fetched through a 5-minute Upload link into memory, then dropped. Only each page's text is saved (`extraction.page_texts`), for the quote check.
Page text
Saved when the job reads the document → never changed → deleted with its job or its owner's account. It stays inside the owner's account like every other record (privacy rule on #41).

Fields

extraction.jobs

One row per attempt to read one file. A retry is a new job, so the history of attempts is kept.

iduuid
The job's ID. Other services store it as job_id.
Primary key. UUIDv7
owner_iduuid
The user whose file it is, from the access token. A plain ID.
file_iduuid
The file in the Upload service. A plain ID: Upload's tables are not reachable from here.
schematext
Which fields were extracted, and so which prompt and rules applied.
invoice-v1 in version 1
referencetextcan be empty
The caller's own label, returned in events. Opaque to Extraction.
1 to 200 characters
statustextdefault 'queued'
Where the job is.
One of queued, processing, extracted, failed
steptextcan be empty
The step running now, or the step that failed. Empty while queued and after success.
One of fetching_file, reading_text, reading_document, checking_rules, saving
attemptsmallintdefault 1
Which try this is within the job: the first, or one of the 2 retries after a temporary failure.
1 to 3
modeltext
The Claude model used, from configuration at the time (EXTRACTION-V1-E3-02 AC3).
1 to 100 characters
prompt_versiontext
The versioned prompt used, so a result can always be traced to its prompt.
Like extract-invoice/v1
pagessmallintcan be empty
Pages sent to the model, from Upload.
1 to 10
fields_totalsmallintcan be empty
How many fields were saved.
0 or more; set when extracted
fields_flaggedsmallintcan be empty
How many need a person's check.
0 to fields_total
tokens_inintegercan be empty
Tokens sent to the model, across the attempt and any repair (EXTRACTION-V1-E3-05).
0 or more
tokens_outintegercan be empty
Tokens the model returned.
0 or more
cost_usdnumeric(10,6)can be empty
Estimated model cost of this job, from the tokens and the model's price per token in configuration. Six decimals because one job costs fractions of a cent.
0 or more
duration_msintegercan be empty
Time from start of processing to the end, in milliseconds.
0 or more
error_codetextcan be empty
Why the job failed, as a stable code.
One of file_unavailable, document_unreadable, no_text_found, model_unavailable, output_invalid, timed_out; set exactly when failed
error_messagetextcan be empty
The plain-language message a person sees.
Set exactly when failed
started_bytextdefault 'person'
Who started the job: the person themselves, which counts toward their free daily quota (EXTRACTION-V1-E3-09), or an app acting for them.
person, or like service:docflow: the delegated token's act claim
held_bytextcan be empty
The app holding the results until it releases them (EXTRACTION-V1-E3-08). Empty: not held.
Like service:docflow; set only at creation, from the delegated token's act claim
released_attimestamptzcan be empty
When the holder released the results. Empty while held.
Set only when held_by is set
created_attimestamptzdefault now()
When the job was asked for.
started_attimestamptzcan be empty
When processing began.
Not before created_at
finished_attimestamptzcan be empty
When the job ended.
Set exactly when extracted or failed; not before started_at
extraction.fields

One row per value read from a document: a header field, or one field of one line item. Never edited after it is saved: this is what the model said, and corrections live in the Human Review service.

iduuid
The field's ID.
Primary key. UUIDv7
job_iduuid
The job that read it.
Foreign key to extraction.jobs, delete cascades
nametext
Which field this is.
A field of the job's schema, for example total or amount
line_indexsmallintcan be empty
Which line item, counting from 0.
0 or more for line-item fields (description, quantity, unit_price, amount); empty for header fields
valuejsonbcan be empty
The value read. Amounts and quantities are decimal strings, dates YYYY-MM-DD, currency a 3-letter code.
A JSON string, or empty when the document does not contain the field
model_confidencenumeric(3,2)
How sure the model said it was.
0 to 1
confidencenumeric(3,2)
The final confidence after rule checks: the lower of the two.
0 to 1, never above model_confidence
source_pagesmallintcan be empty
The page the value was read from.
1 to the job's page count; empty when there is no value
source_quotetextcan be empty
The exact text on the page the value came from: the evidence a person checks.
1 to 500 characters; empty when there is no value
flaggedbooleandefault false
Whether a person needs to check it.
True exactly when there is at least one reason
flag_reasonstext[]default '{}'
Why it was flagged, for example 'Total ≠ subtotal + tax' or 'Low confidence (0.62)'.
Plain-language reasons
created_attimestamptzdefault now()
When it was saved.
extraction.page_texts

The text of each page a job read: from the PDF's text layer, or by OCR for scans and photos. Used to check that every quote is really in the document.

job_iduuid
Which job read it.
Part of the primary key; foreign key to extraction.jobs, delete cascades
pagesmallint
Which page.
1 to 10; part of the primary key
sourcetext
Where the text came from. OCR text can contain reading mistakes, which the eval set measures.
text_layer or ocr
texttext
The page's text.
Up to 100,000 characters; may be empty for a blank page
created_attimestamptzdefault now()
When it was read.
extraction.inbound_events

One row per platform event Extraction has acted on, so a repeated delivery has no effect.

event_iduuid
The event's ID, from the sender.
Primary key
typetext
What happened.
1 to 100 characters
created_attimestamptzdefault now()
When Extraction processed it.

The service template also gives Extraction audit_events, idempotency_keys and outbound_events. Extraction writes job.created, job.completed and job.failed to audit_events, and announces extraction.job.completed and extraction.job.failed through outbound_events. POST /jobs needs no idempotency key: a second call for the same file returns the running job.

Data model level: business rules the service guarantees

  • A job only ever reads a file its owner can read: the background job fetches it through Upload with a delegated token for the owner (upload:read, act: service:extraction), so Upload's ownership check applies and no user token is stored.
  • At most one job per file and schema is queued or processing at a time, so the same document is never read or billed twice at once.
  • A job only moves forward: queued → processing → extracted or failed. A failed job is never restarted; a retry is a new job.
  • Fields are written once, all together, when a job succeeds, and never changed. A failed job has no fields.
  • A field's final confidence is never higher than the model's own, and a field is flagged exactly when it has a reason.
  • Every value that is present has a page and a quote, so a person can always see where it came from.
  • Amounts are kept as decimal strings, never floating-point numbers.
  • Deleting a user's account deletes their fields, which hold document content. Their jobs are kept with IDs, counts, tokens and cost only, for the cost records.
  • Each job records the model and prompt version it used, so any result can be traced and re-run.
  • A person may start 3 jobs a day themselves, free (EXTRACTION-V1-E3-09); jobs an app starts for them count toward the app. The quota is checked when a job is created and counted from started_by and created_at, so it cannot be dodged by retrying.
  • A held job shows its owner only the flagged fields until the holding app releases it (EXTRACTION-V1-E3-08). Only a delegated token can place a hold, and only the holder can release it, so a person cannot read held results early and cannot lift a hold themselves. Extraction never knows the reason for a hold.

What is deliberately not stored

  • The document itself: it stays in the Upload service. Only its page text is kept, for the quote check.
  • The model's raw answer: only the validated fields are saved, so invalid output is never kept.
  • The prompt text on each job: only its version; the text lives in `prompts/`.
  • Document content in logs: logs carry IDs, counts and timings only.