Inconsistent Line-Item Extraction from the Same Invoice
Hi LandingAI team,
I’m currently using LandingAI to parse and extract structured data from invoice documents. My workflow consists of two steps:
Parse the invoice document into Markdown using dpt-2-latest
Extract structured data from the generated Markdown using extract-latest and a custom JSON schema
Here is the relevant code:
# Step 1: Parse document → Markdown
parse_result = self._client.parse(
document=Path(tmp_path),
model="dpt-2-latest",
)
# Step 2: Extract structured data against the caller's schema
extraction_result = self._client.extract(
schema=json.dumps(schema),
markdown=parse_result.markdown,
model="extract-latest",
)
extracted = extraction_result.extraction or {}
return extracted, parse_result.markdown or ""
Issue
For the same invoice document, the extraction results are sometimes inconsistent.
In particular, the line_items are usually extracted correctly, but occasionally some line items are missing or not extracted as expected. Since the input invoice is identical, I would expect the extraction results to be consistent across multiple runs.
Questions
Could you please help me understand:
Is extract-latest deterministic when the same Markdown and schema are provided multiple times?
Are there any parameters or settings available to make the extraction more deterministic or consistent?
Could the inconsistency be caused by the dpt-2-latest parsing step—for example, if the generated Markdown differs slightly between runs?
What is the recommended approach for reliably extracting all invoice line items, especially for invoices with complex tables or multi-page line-item sections?
Are there any schema-design recommendations or prompting techniques that can improve the consistency of line_items extraction?
Would using a specific/fixed model version instead of *-latest help improve consistency?
I’d also appreciate any recommendations for debugging this issue. For example, should I compare the generated Markdown across multiple runs to determine whether the issue originates from the parsing step or the extraction step?
The main goal is to ensure that the same invoice consistently produces the same complete set of line items across multiple runs.
Thanks in advance for any guidance!