
Adaptive BOM Ingestion for Customer Spreadsheets
Hardcoded column indices fail on the second customer file, so I built a four-step heuristic pipeline that finds the header, maps the columns and fails loudly when it can't.
- Published
- March 16, 2026
- Author
- Hrushiekesh Reddy Kanjula
- Read time
- ~4 min
- Category
- engineering

My first BOM parser assumed data started on row 1, column A. It worked for one customer.
The second customer had a logo in rows 1–4, headers in row 5 and data from row 6. The third merged cells. The fourth used a different header name for every column. By the fifth, I had two options. I could maintain five parsers, or build one adaptive engine. I built the engine. It is harder to write, but much easier to maintain.
About 80% of imports now auto-approve on the first pass. The rest go to an engineer with the low-confidence decisions highlighted.
Why hardcoded parsers fail
A BOM spreadsheet carries the same information everywhere: reference designator, quantity, part number, manufacturer, description. The layout is not standardized. Customers use their own ERP templates, export from different CAD tools and add custom columns.
A hardcoded parser encodes assumptions that hold for one customer. df.iloc[3:, 2] assumes data starts at row 3, column 2. When a customer adds a revision note at the top, the parser misreads the file. Often it raises no exception. It just produces garbage.
Silent misreads are expensive in manufacturing. A misidentified reference puts a part in the wrong place on the PCB, and that becomes a field return. The parser has to get it right or fail loudly.
Step 1: Density auto-detection
Don't assume where the data starts. Read the first 30 rows and score each one by how many BOM keywords it contains. The keywords come from a curated list: ["qty", "quantity", "ref", "designator", "part", "number", "description", "manufacturer", "value", "package"].
def detect_header_row(df_raw: pd.DataFrame) -> int:
keyword_set = {"qty", "quantity", "ref", "designator",
"part", "number", "description", "value"}
scores = []
for i, row in df_raw.head(30).iterrows():
row_text = " ".join(str(v).lower() for v in row if pd.notna(v))
score = sum(kw in row_text for kw in keyword_set)
scores.append((score, i))
return max(scores, key=lambda x: x[0])[1]The row with the highest score is the header row. This handles logos, revision tables, title blocks and any other preamble above the data.

Step 2: Weighted column scoring
Next, each column has to map to a field in the internal schema. The header name is a strong signal. A column called "Qty" is almost certainly quantity. But some exports use numeric column identifiers, and some customers use non-standard names.
So the scorer uses two signals:
- Header similarity, fuzzy-matched against a dictionary of known names for each field.
- Data pattern. A column of strings like
"C101","R47"and"U3"is a reference designator column, whatever its header says.
Each column gets a confidence score for each possible field. Assignments go greedily from highest confidence to lowest, so no field is assigned twice. Columns below the confidence threshold are flagged as unknown and left out of the import.
Step 3: Array dimensionality
This one bit me in production. With xlwings, a single cell returns a scalar. A one-row range returns a 1D list. A multi-row range returns a 2D list of lists.
Code that expects 2D and gets 1D throws an index error. Code that expects 1D and gets 2D iterates over inner lists as if they were values. The fix is a wrapper that coerces any range output to 2D before processing:
def normalize_xlwings_output(raw) -> list[list]:
if not isinstance(raw, (list, tuple)):
return [[raw]]
if raw and not isinstance(raw[0], (list, tuple)):
return [[v] for v in raw]
return [list(row) for row in raw]One call at the ingestion boundary removes a whole class of runtime errors.

Step 4: Component deduplication
Customer BOMs often contain duplicates. The same reference designator appears twice, or the same part number sits on several lines that should be one. The last step is a deduplication pass:
- Group rows by reference designator.
- If a group has conflicting part numbers, flag it for human review.
- If a group has matching part numbers, merge the quantities.
- Give each resolved entry a unique internal BOM line ID.
The output is a clean, uniquely keyed dataset ready for the normalization pipeline from the previous post. I kept the two pipelines separate on purpose. Ingestion handles structure. Normalization handles content.
Confidence scores and the rejection queue
Every import produces a confidence report. It has per-column mapping confidence, header detection confidence and an overall score.
| Overall confidence | What happens |
|---|---|
| Above 90% | Auto-approved and passed to normalization |
| 70–90% | Flagged for engineer review, with the low-confidence decisions highlighted |
| Below 70% | Rejected, with a diagnostic report on what the system couldn't work out |

Engineers only see the files that need judgment. The files that need review are mostly legacy ones, from customers who haven't updated their ERP export templates in a decade. When the engine works, nobody notices it. When it doesn't, it saves hours of manual reformatting on each exception.