Skip to content
← Back to activity

Public problem

textractor raises `KeyError: 'Geometry'` when an expense field has an empty value

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

I call textract.start_expense_analysis on a multi-page invoice PDF stored in S3. When I access document.expense_documents, I get KeyError: 'Geometry'. Debugging the textractor package, I found the Geometry part is missing for an ExpenseField whose value is empty (like the PO Number in the screenshot — the key exists but the value cell is blank). Why does an empty cell crash the parse?

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

This was a real bug in textractor's expense parser. Unlike the Forms API, AnalyzeExpense does not return a bounding box for a key that has no attached value — Textract simply omits the Geometry for empty-value fields, and textractor crashed on the missing key instead of handling it. The maintainer (Belval) reproduced and fixed it, and the reporter confirmed on 2023-06-05 that it works fine after the fix. So update textractor to the fixed version. Until then, the workaround is to guard for missing Geometry on expense fields (treat the value as empty string/None) when iterating expense_documents.

Source: https://github.com/aws-samples/amazon-textract-textractor/issues/195

Source: https://github.com/aws-samples/amazon-textract-textractor/issues/195