An AI inspection tool, a document checker, or an automated classifier is a measurement system. It decides whether something is good or bad, so it needs the same validation as a gauge or an inspector: does it catch the defects, how often does it raise false alarms, and does it stay that way?
This guide explains the confusion matrix and the measures from it (recall, specificity, precision, accuracy, kappa), how to design a validation with an agreed standard and enough defects, why precision falls when defects are rare (the prevalence trap), how to choose a threshold by cost, and how to keep a tool valid. A worked example validates an AI visual inspection assist against human inspectors, with exact intervals and the monthly cost of each kind of error.
All figures are illustrative. It complements the AI in Manufacturing Quality guide, which covers the use cases.
Before You Start
Treat the AI Like a New Inspector
An AI inspection tool, a document checker, or an automated classifier is a measurement system. It decides whether a part, a record, or a claim is good or bad. That means it needs the same validation as a gauge or an inspector: does it find the defects, how often does it raise false alarms, and does it stay that way over time? Quality engineers already know how to answer these questions. The AI in Manufacturing Quality guide covers the use cases; this guide covers how to prove a tool is good enough.
Two Kinds of Error
A miss (escape) lets a bad part through. A false alarm stops or re-inspects a good one. They cost different amounts.
Prevalence Changes Everything
A tool that looks good on a test set rich in defects can bury you in false alarms when defects are rare.
A Standard Is Needed
You cannot judge the AI without a trusted answer for each test item, and the experts may not agree.
Validation Never Ends
Products, lighting, suppliers, and models change. Keep checking.
The Confusion Matrix and Its Measures
Run the tool on a set of items whose true status is known, and count the four outcomes.
| Measure | Calculation | What it answers |
|---|---|---|
| Recall (sensitivity) | True positives ÷ all defects | Of the defects, how many does it catch? The opposite is the escape rate |
| Specificity | True negatives ÷ all good items | Of the good items, how many does it pass? The opposite is the false alarm rate |
| Precision (positive predictive value) | True positives ÷ all flagged items | When it flags something, how often is it really defective? |
| Accuracy | Correct decisions ÷ all items | Overall agreement. Misleading when defects are rare |
| Kappa | Agreement beyond chance with the standard | How well it agrees with the standard, allowing for luck; see MSA |
Designing the Validation
- Define the standard. What counts as a defect, with photos and limit samples. Have two or more experts label every test item independently and settle disagreements.
- Measure the experts. Their agreement with each other (kappa) is a ceiling on what any tool can show. If the experts disagree, fix the standard first.
- Build a representative test set. Include every defect type and the borderline cases, and parts from different lots, shifts, suppliers, and lighting. Keep the set separate from anything used to set up the tool.
- Enough defects. To show a recall of at least a target with no misses at 95% confidence you need a minimum number of defects (table below). More if you expect some misses.
- Run it blind, as it will run in production, and record every outcome.
- Report intervals, not just percentages, and the cost of each kind of error.
- Set the acceptance criteria in advance, with a stop rule.
| To show recall is at least | Defects needed with none missed (95% confidence) |
|---|---|
| 90% | 29 |
| 95% | 59 |
| 98% | 149 |
| 99% | 299 |
These are the same zero-failure sample sizes used for reviewing AI output in the human-in-the-loop guide, applied to defects. Rare defects make this hard: if only 1% of parts are bad, finding 59 defects means inspecting about 5,900 parts, so use a defect-enriched set and say so.
Worked Example: AI-Assisted Final Inspection at Riverside Plant
Riverside Plant, an illustrative 140-employee metal fabrication and assembly plant, tested an AI visual inspection assist on 400 parts whose status two inspectors and an engineer had agreed on: 60 defective and 340 good (a deliberately enriched set with 15% defects). Figures are illustrative.
| Measure | AI tool | Human inspectors (same parts) |
|---|---|---|
| Recall | 90% | 85% |
| Specificity | 95% | 97.9% |
| Kappa against the standard | 0.79 | 0.84 |
What this means. The AI catches more defects than the inspectors do (90% against 85%) but raises more false alarms (5% against about 2%), so its overall agreement with the standard is slightly lower. It is a different trade-off, not simply a better one.
The Prevalence Trap
The test set had 15% defective parts. Production has about 1.5%. Precision depends on how common defects are, so a tool that looks good on the test set behaves very differently on the line.
| Per month at 10,000 parts and 1.5% defective | AI tool | Human inspectors |
|---|---|---|
| Defects | 150 | 150 |
| Escapes (defects passed) | 15 | 22.5 |
| False alarms to re-inspect | 493 | 203 |
| Flags that are real (precision) | 22% | 39% |
| Cost at $400 per escape and $3 per false alarm | $7,478 | $9,608 |
The decision. On cost alone the AI saves about $2,131 a month, and it finds 7.5 more defects. But the line would re-inspect about 493 good parts a month, and four in five flags would be false. The plant used the tool as an assistant: its flags go to an inspector for a second look, with a goal to tune the threshold and re-test before it is allowed to reject parts on its own. Use the AI Classifier Validation Calculator to run these figures for your own tool.
Thresholds and Costs
- Most tools give a score, and a threshold turns it into flag or pass. Moving the threshold trades escapes for false alarms.
- Choose the threshold by cost, not by the vendor default: the cost of an escape against the cost of a false alarm, at your real defect rate.
- Set the threshold on one data set and test it on another. A threshold tuned on the test set overstates performance.
- For safety-critical defects, set the threshold to protect recall, and add a second check.
Keeping It Valid
| Control | How | Why |
|---|---|---|
| Master samples | Insert known good and known bad parts at intervals | A direct check, as with any gauge; see the seeded-error idea in the human-in-the-loop guide |
| Audit sample | Have inspectors re-check a random sample of passed and flagged items | Shows the true escape and false alarm rates |
| Control chart | Chart the share flagged, and the audit error rate, over time; see SPC Control Charts | A shift can mean drift in the tool or in the process |
| Change control | Re-run the test set after any change to the tool, camera, lighting, or product | Silent change is a main risk; see Management of Change |
| Periodic re-validation | Repeat the study at a set interval and after incidents | Conditions change |
Common Mistakes
Reporting Accuracy Only
A high accuracy that hides missed defects.
A Test Set Unlike Production
Too few defects, or only the easy ones.
Forgetting Prevalence
Not working out how many flags will be false at the real defect rate.
No Agreed Standard
Judging the tool against inspectors who disagree.
Tuning on the Test Set
A threshold that looks great on the data it was set on.
Validating Once
No checks after the process or the tool changes.
Self-Assessment Questions
- Do we have an agreed standard, and how well do our experts agree with each other?
- Do we report recall, specificity, and precision with intervals, and not accuracy alone?
- Have we worked out the false alarms and escapes per month at our real defect rate?
- Did we choose the threshold by cost, and test it on separate data?
- How will we know if the tool drifts?
AI for Quality and Inspection: Frequently Asked Questions
How do I validate an AI inspection system?
Agree a standard for what is defective, have experts label a representative test set independently, run the tool blind on it, and count true and false positives and negatives. Report recall, specificity, and precision with exact confidence intervals, check the experts agree with each other, and work out what the results mean at your real defect rate.
What is the difference between recall and precision?
Recall is the share of real defects the tool catches. Precision is the share of the tool’s flags that are real defects. A tool can have high recall and low precision, which means it catches most defects but raises many false alarms, especially when defects are rare.
Why is accuracy a poor measure for inspection?
When defects are rare, a tool that passes everything is almost always right, so accuracy looks high while recall is zero. Always report recall and specificity, and the cost of each kind of error.
How many defective samples do I need?
To show a recall of at least 90%, 95%, 98%, or 99% with no misses at 95% confidence you need at least 29, 59, 149, or 299 defects respectively. If you expect some misses you need more, or you should use an exact interval on what you observe.
How do I keep an AI inspection tool valid over time?
Insert known good and bad samples regularly, re-inspect a random audit sample, chart the share flagged and the audit error rate on a control chart, re-run the test set after any change to the tool, camera, lighting, or product, and re-validate on a schedule.
Sources and Further Reading
- AIAG, Measurement Systems Analysis Reference Manual (4th ed., 2010), on attribute agreement analysis and kappa.
- Cohen, J., “A coefficient of agreement for nominal scales,” Educational and Psychological Measurement 20(1), 1960.
- Clopper, C. J. and Pearson, E. S., “The use of confidence or fiducial limits illustrated in the case of the binomial,” Biometrika 26, 1934.
- Altman, D. G. and Bland, J. M., “Diagnostic tests 1: sensitivity and specificity” and “Diagnostic tests 2: predictive values,” BMJ 308, 1994.
- National Institute of Standards and Technology, AI RMF 1.0 (NIST AI 100-1), the Measure function on testing and evaluation.
- Montgomery, D. C., Introduction to Statistical Quality Control (Wiley), on acceptance sampling and control charts.