Somewhere in your codebase there is a function that walks a Textract response. It collects the KEY_VALUE_SET blocks, follows each key to its value, joins the words underneath, and compares the result against a list of labels someone wrote down years ago: Invoice No., Invoice #, Inv. Number. Next to it sits another function that rebuilds tables from cells, and a third that turns confidence scores into a review flag.
That code is the real subject of an AWS Textract migration. Swapping the service that reads the page is the easy part. What changes is the output contract: Textract returns a graph of blocks, and a schema-based extraction API returns the fields your system of record already expects. This piece maps one onto the other, so you can see which parts of your pipeline go away and which parts move.
What a Textract response is
The AWS documentation describes the response as a list of Block objects. Each block has an ID, a type, the page it sits on, a confidence score, a geometry, and a list of relationships to other blocks by ID. The types that matter for extraction are these:
- Text —
PAGE,LINE, andWORD. Words carry the text; lines and pages group them throughCHILDrelationships. - Forms —
KEY_VALUE_SET, withEntityTypesset toKEYorVALUE, andSELECTION_ELEMENTfor check boxes, with aSelectionStatusofSELECTEDorNOT_SELECTED. - Tables —
TABLE,CELL, andMERGED_CELL, plusTABLE_TITLEandTABLE_FOOTER. Cells carryRowIndex,ColumnIndex,RowSpan, andColumnSpan, and a cell can be marked as aCOLUMN_HEADER. - Queries and layout —
QUERYandQUERY_RESULT, linked by anANSWERrelationship,SIGNATURE, and theLAYOUT_*family for reading order.
Two details in that structure explain most of the code you wrote. A KEY block holds no text of its own: the documentation's example key reaches its label only through CHILD relationships to WORD blocks, so the label has to be assembled before it can be matched. And the key and its value share one confidence score, from 0 to 100, which says how sure the service is about the pair, not about whether the pair is the field you wanted.
For multipage documents, the asynchronous GetDocumentAnalysis call returns at most 1,000 blocks per response and a NextToken for the rest, and a job ID is valid for 7 days. Your pipeline already has a loop for that, and somewhere to keep the ID while it waits.
Block to field, row by row
The table below maps each Textract construct to what your code does with it today and to what a field in a declared schema carries instead. Field names are illustrative.
| Textract construct | What your code does today | What the schema field carries |
|---|---|---|
KEY_VALUE_SET with EntityTypes KEY, and its VALUE relationship | Assembles the key text from child words, matches it against a label list, then follows the relationship to the value | A named field such as invoice_number. The label on the page is no longer your lookup key. |
KEY_VALUE_SET with EntityTypes VALUE, and its child WORD blocks | Joins the words, then parses dates, amounts, and identifiers in your own code | A typed value: a date, a number, or a string with the format the schema declares. |
SELECTION_ELEMENT | Finds the key next to the box, reads SELECTED or NOT_SELECTED | A boolean field, named for the question the box answers. |
TABLE, CELL, MERGED_CELL, and COLUMN_HEADER | Rebuilds the grid from row and column indexes, resolves spans, decides which row is the header, maps columns by header text | An array of objects, one per line item, each with typed properties. |
QUERY and QUERY_RESULT through ANSWER | Asks a question in natural language and takes the answer text | The same named field, with a type. A query is a question; a schema field is a question with a declared answer shape. |
Confidence, 0 to 100, per block | Compares against a threshold to flag review | A confidence per field. Check the scale: the example on our extraction API page shows 0.99, not 99. |
Page and Geometry | Draws a highlight from ratios of the page width and height | A citation per field: the page and the region the value was read from. |
SIGNATURE | Records that a signature-shaped region exists | A field for the signature you care about, tied to its page and region. |
LAYOUT_* | Feeds reading order into search or retrieval | Nothing, unless a consumer needs it. Field extraction does not depend on it. |
Coordinates deserve their own care. Textract expresses a box as ratios of the page width and height, and other APIs use other conventions, so treat the convention as part of the contract and check highlights on rotated and multipage documents before a reviewer relies on them.
What migrates is the consumer, not the OCR
Before you choose anything, list every place in your code that reads a block. In most pipelines that list falls into five groups, and each one has a different fate:
- Label dictionaries — the lists of key strings per document type. With a schema they are deleted, and the variation they absorbed moves into the extraction.
- Table rebuilders — the code that turns cells into rows. Also deleted, but keep its test documents: merged cells and multi-page tables are exactly what the new output must still get right.
- Parsers and normalizers — date, amount, and identifier parsing. Some of it moves into the schema's types; keep the business rules that are yours, such as which date counts as the due date.
- Review thresholds — the numbers that decide what a person sees. They have to be set again on the new scale, from your own review data, not converted by dividing by 100.
- Highlights and audit — the screens and records that show where a value came from. They switch from block geometry to field citations, which is a change to stored data and has to be planned like one.
The last group is the one teams forget. If old records point at Textract block IDs, those IDs mean nothing to the new system. Decide whether historical records keep their original evidence as it was, or are re-extracted, before the first document goes through the new path.
Run both on the same packet
The comparison that matters is not raw text against raw text. It is the final field your system stores, after your Textract code has run, against the field the schema returns. Anything else measures the OCR and ignores the code you are trying to retire.
- Use your own documents — take the hardest 25 from production, not a demo set, including the ones that already go to review.
- Run in shadow — keep Textract serving the live path, write the new output to a side table, and diff field by field.
- Count review effort — for each document, record which fields each path would have sent to a person, and why.
- Read the disagreements — a disagreement is not automatically an error on the new side; sometimes it is a label your dictionary matched wrongly for years.
Our document extraction benchmark guide describes the method in more detail. We cite no accuracy figures here, because the only ones that would mean anything are the ones from your documents.
When staying on Textract is the better call
Not every pipeline should move. If what you need is text with geometry, if your documents fit Textract's prebuilt analysis, and if your team is AWS-native and happy to own the code between blocks and fields, the code you have is doing its job. Amazon also offers Bedrock Data Automation, which sits above Textract and returns schema-shaped output, if the goal is fields without leaving AWS. A hybrid is reasonable too: keep Textract for OCR and add an extraction step on top. Our AWS Textract alternatives page sets out where it fits and where it breaks.
Before you switch the live path
- An inventory of block readers — every function that reads a Textract block, sorted into the five groups above.
- A schema per document type — written from the fields your system of record stores, not from the labels printed on the page.
- Thresholds set on the new scale — from shadow-run review data, per field.
- A plan for old evidence — what happens to records that cite block IDs.
- A rollback — the Textract path stays deployable until the shadow diff is quiet for long enough to trust.
If part of what you are replacing is Textract Queries, where people ask a document a question, it helps to separate the questions a person reads from the fields a system stores. Our piece on chat with PDF versus document extraction draws that line.
