
Fuzzy Matching AOI Defect Data to Your Component Library
AOI reports carry part numbers that almost match the component library, so I parse the columns dynamically and match in three tiers.
- Published
- March 23, 2026
- Author
- Hrushiekesh Reddy Kanjula
- Read time
- ~4 min
- Category
- engineering

AOI defect reports don't use your component library's part numbers. The machine logs the part number as it appears in the placement program. That might be "C0402-100N-10V". Your canonical library entry for the same part is "CAP|100N|10%|-|0402|10V|X7R". The two have to be linked before the defect data is useful.
That takes fuzzy matching. Doing it reliably at scale takes more than calling fuzz.ratio() and hoping for the best.
Automated Optical Inspection (AOI) is the last gate before a PCB ships. The machine photographs every placement, compares it to the expected geometry and flags what looks wrong. That includes a rotated capacitor, a missing resistor or a misaligned IC. It writes a defect report for every board.
The dynamic column parser
The report has to be parsed first. AOI output is inconsistent across vendors and firmware versions. Column order varies. Header names change between software updates. Some machines export CSV. Others export a proprietary tab-delimited format with embedded metadata.
The parser scores each column on two signals: the header string and the data pattern. If every value matches [A-Z]\d{1,4} (like C101, R47, U3), the column is almost certainly the Reference Designator, whatever the header says. A column of values like "0402" and "SOT-23" is the Package column. Because it infers from content, it keeps working when a vendor renames every column.
def infer_column_role(series: pd.Series, header: str) -> str:
# Header name match first
header_map = {"ref": "reference", "designator": "reference",
"part": "part_number", "defect": "defect_type"}
for keyword, role in header_map.items():
if keyword in header.lower():
return role
# Content pattern inference
ref_pattern = re.compile(r'^[A-Z]{1,2}\d{1,4}$')
if series.dropna().apply(lambda x: bool(ref_pattern.match(str(x)))).mean() > 0.8:
return "reference"
return "unknown"
Normalize first
Fuzzy matching works better when both sides are normalized. Before any comparison, the AOI part number and the library key go through the same pass:
- Remove manufacturer prefixes (
"TI-","MFR:","PN:"). - Standardize separators (hyphen, underscore, slash become a single hyphen).
- Strip trailing qualifiers (
"-T","-TL","-REEL"for tape-and-reel packaging). - Uppercase everything.
This raises the match rate at tiers 1 and 2. Fewer cases fall through to tier 3 or return no match.
Three-tier matching
Each AOI part number is matched against the canonical library in three tiers, from most to least confident.
Tier 1, exact match. After normalizing, try a direct dictionary lookup. It is fast and unambiguous. About 60% of AOI part numbers match exactly after normalization.
Tier 2, token sort ratio. For the rest, compute the token sort ratio with RapidFuzz. It sorts the words in both strings alphabetically before comparing. So "10K RES 0402" and "RES 0402 10K" score 100, even though they differ character by character. This handles most manufacturer prefix variations and field order differences.
Tier 3, partial token match. Sometimes the AOI part number is a subset or superset of the library entry. This is common with manufacturer part numbers that embed dimensional codes. Partial token matching finds the best candidate in the right component family. A minimum threshold of 85 prevents false positives.
from rapidfuzz import fuzz, process
def match_part_number(aoi_pn: str, library: dict) -> tuple[str, float]:
normalized = normalize_part_number(aoi_pn)
# Tier 1: exact
if normalized in library:
return library[normalized], 100.0
# Tier 2: token sort
candidates = process.extractOne(
normalized, library.keys(),
scorer=fuzz.token_sort_ratio,
score_cutoff=85
)
if candidates:
return library[candidates[0]], candidates[1]
return None, 0.0
When nothing matches
If all three tiers fail, the defect record is flagged "unresolved" and goes into a manual review queue. The queue shows the AOI part number next to the top five library candidates, ranked by similarity score, with color-coded confidence bands. An engineer confirms or corrects the match with one click.
Each correction is written to a custom match table. It maps {aoi_part_number → library_id} and short-circuits future lookups for that string. The first time "VISHAY-10K-0402" appears, a human resolves it. After that, the lookup returns the right library entry instantly.

The output
Once every defect record links to a library entry, defects can be grouped by component family, package size or placement head. A record that was "Tombstone on C0402-100N-10V at R3C5" becomes "Tombstone on CAP|100N|10%|0402 — matched to library ID 4821, placed by Head 3 Nozzle A at 14:32:07".
That link turns the AOI output from an inspection log into a feedback loop for production quality.