Extracted Line Items: Don't Let Sorting Break Row Order
The amounts in the two rows of details are identical, which does not indicate that they are duplicate data; nor does the sorted table, which appears more organi
Extracting line items from a document is one task, but keeping each row tied to its source while you sort, filter, or translate is harder. Identical amounts can appear on different lines, and a neatly sorted table may no longer match the original text row by row. This guide is for anyone building or checking a table of detail records, such as invoices, order lines, or other tabular data pulled from PDFs.
The examples use synthetic samples. Keep the original copies of important documents and verify your output against your own acceptance criteria before you rely on it.
You will learn why amounts and product names are poor row identifiers, how to give each row a stable source identity, how to handle repeated headers and subtotals, and how to verify translated tables against their sources.
How do you keep extracted line items in the right order? The short answer
Give every row a stable source identity, such as page, table number, and source row number, and sort only in a display view, never in the source data.
| Your situation | What to do | Why |
|---|---|---|
| Two rows have the same amount | Compare their source positions before you treat them as duplicates | Identical amounts do not prove duplicate data |
| You need to sort the table by amount | Create a display view and leave the source data alone | Sorted sequence numbers should not be written back into the original source |
| Repeated headers or subtotals appear in the details | Remove them with explicit, explainable rules and keep the excluded rows | Reviewers can then spot accidental deletions |
| You translated a table | Align rows by source ID, then check row-column relationships, quantities, and units | Product names can change or repeat after translation |
| The row count is wrong | Find the missing segment first (merged cells, blank rows, filters) | Copying values from the previous row hides the real cause |
Why row identity matters more than the fields
When you extract detailed records, the easiest thing to overlook is not the fields themselves but the relationships between rows and their sources. The amounts in two rows may match, and the sorted table may look more organized, yet neither fact shows that the rows still correspond to the original text line by line.
Use a stable row identity
Keep the source page, table number, and source row number for each detail entry. You can also combine these into a single stable identifier. Product names and amounts can repeat, so they are unsuitable as standalone identifiers.
Keep sorting in a display view
When downstream systems need to sort by amount:
- Create a display view that sorts the rows.
- Leave the source records in their original order.
- Do not write the sorted sequence numbers back into the original source.
Do not rely on array order or uniqueItems
A JSON array keeps its order. However, in a schema, uniqueItems does not mean "this particular field is unique." Two objects remain distinct as long as any of their other fields differ, so you must check field-level uniqueness separately. For details, see the JSON Schema array reference.
Working through a set of details with the same amount
Rows with identical amounts can still come from different sources. The following check compares source identity rather than amounts:
from collections import Counter
rows = [{"source_id": "p1-t1-r1", "item": "Bolt", "amount": "10.00"},
{"source_id": "p1-t1-r2", "item": "Nut", "amount": "10.00"}]
def check_ids(items):
counts = Counter(row["source_id"] for row in items)
return [key for key, count in counts.items() if count > 1]
assert check_ids(rows) == []
assert len(rows) == 2
assert check_ids(rows + [dict(rows[0])]) == ["p1-t1-r1"]
display = sorted(rows, key=lambda row: row["item"], reverse=True)
assert [r["source_id"] for r in rows] == ["p1-t1-r1", "p1-t1-r2"]
assert {r["source_id"] for r in display} == {r["source_id"] for r in rows}
This is an identity check for synthetic data. It is not a table recognizer. It deliberately does not deduplicate identical amounts, and it does not treat display order as source order.
When you generate true source IDs, account for file versions. Otherwise, the same page and the same line in two different versions could be mistakenly treated as the same piece of evidence.
When the number of lines is wrong, find the missing segment first
Use this table to decide what to check before you change any data:
| phenomenon | should check | should not immediately adopt |
|---|---|---|
| amount duplicate | Whether it is a different project or a different source line | deduplication by amount |
| source ID duplicate | whether it has been imported repeatedly or mapped incorrectly | randomly adds a new ID |
| number of lines reduced | Merge cells, blank rows, and filtering rules | uses the previous line to complete |
| sequence variation | Is it merely for display purposes? | overwrites the original line number |
Handling headers, notes, and subtotals that cross pages
Repeated header rows, continuation notes, and subtotal rows can end up in your detail array. Removing them requires rules you can explain. Neither "first row" nor "shorter text" is enough on its own.
Keep the excluded rows and the reason you excluded each one. Reviewers can then catch accidental deletions, rather than tracing back only after the final total fails to match.
Verifying translated tables against the source
A multilingual detail table should be alignable by source ID. Do not rely only on the translated product name to look up a row. When you translate tabular documents with OmniDoc (product entry point), check row-column relationships, quantities, and units as separate items. The source identifier described here is an external engineering convention, not a description of the platform's internal implementation.
📊 At a glance
| Approach | When it helps | Why not to use it alone |
|---|---|---|
| Stable source ID (page, table, row) | Tracing each row back to its origin | Requires a rule for file versions |
| Amount matching | Spotting rows that might be related | Identical amounts can come from different sources |
| Display-only sorting | Presenting rows in a useful order | Must not overwrite the original line numbers |
| Explained exclusion rules | Removing headers and subtotals | "First row" or "shorter text" alone is not enough |
🎯 Which approach fits you?
If you need to sort by amount
Build a display view and keep the source line numbers unchanged.
If two rows have the same amount
Compare their source pages, table numbers, and row numbers before you decide they are duplicates.
If you are translating a table
Align the rows by source ID and check quantities and units separately.
❓ FAQ
1. Can identical amounts show that two rows are duplicates?
No. Identical amounts do not show that rows are duplicates. Compare their source positions instead.
2. Should I write sorted sequence numbers back into my data?
No. Keep sorting in a display view and leave the original line numbers unchanged.
3. Does uniqueItems make each field in my array unique?
No. In a schema, uniqueItems does not mean a particular field is unique. Check field-level uniqueness separately.
4. What should I do with repeated headers and subtotals?
Remove them with rules you can explain, and keep the excluded rows along with the reason for each exclusion.
📝 Summary
Stable source identities let you sort, filter, and translate line items without losing track of where each row came from. Keep the source order intact, sort only in display views, and verify every translated table against its original.
Try it now: upload a document and get it translated with the layout intact


