https://www.boundaryml.com logo
Best practices for table extraction?
# help
a
Table extraction from PDFs is central to our pipeline, but since ~every tool is imperfect, we end up going to an LLM to batch-correct all of the rows in our extracted tables. The current prompt looks like the below, where each column header is a field on
CorrectedData
. The big issue is that this takes a long time! Any suggestions for how I might make this process faster without sacrificing accuracy?
Copy code
class CorrectedData {
  @@dynamic
}

class CorrectedRowsData {
  rows_corrected int @description("How many rows were corrected/modified from the original Camelot output")
  correction_notes string[] @description("VERY BRIEF notes about corrections made (e.g., 'merged cells in rows 5-7', 'removed phantom column 3'). MAX 200 chars total.")
  corrected_data_rows CorrectedData[] @description("ALL data rows corrected to match visual. Each inner array has exactly len(column_headers) cells in correct order. Headers already removed. Each row MUST have a non-empty value in the 'code' column (door mark/number or unit type code) to be included.")
}
function CorrectTableRows(
  camelot_rows: string[],
  broad_schedule_type: "unit" | "door" | "window",
  schedule_image: image
) -> CorrectedRowsData {
  client Gpt4_1
  prompt #"
    You are correcting table rows from a {{ broad_schedule_type }} schedule.
Something I tried is-- provide X headers in an array, and then have the model return arrays of length X per row in the table. I sometimes saw arrays with the wrong length be returned, so I scrapped this approach
b
How large are your requests right now? Like how much data are you feeding into the request
You can also rely on [semantic streaming](https://docs.boundaryml.com/guide/baml-basics/streaming) to make the UX feel better
Also, I would remove
rows_corrected int
from your output: I would actually be surprised if this field was consistently correct
a
We show the whole thing to the user after it's done becuase it's all in an async pipeline. We generally feed in ~25 rows of data, with anywhere from 5-20 columns.
Curious what your thoughts are on prompt formatting, etc.!
b
How big is each row?
I think I'd probably need to understand the use case better to make a more targeted section, but I suspect in your case the problem is really just that image processing is going to be slower
And you may just need to retool your UX a bit to acknowledge that
j
Pdfplumber is pretty good at table extraction
a
I'm looking for more baml-y tricks. One example I got from @Vaibhav (BAML 🐑) is-- add "no quotes on keys" in the json output, which saves time. Anything like that?
v
Most of it really goes to just simplifying your schema
Eg you can use @alias
With simpler encodings