Analyze manufacturing defect detection and quality control systems — computer vision inspection pipelines, SPC control charts, Six Sigma process capability (Cp/Cpk), defect classification taxonomies, root cause analysis tooling, and measurement system analysis. Use when auditing manufacturing QC or vision-inspection software, or the user asks 'check our SPC charts', 'is our Cpk calculation right', or 'review our defect classification pipeline'.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Defect Detection?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tinh2-defect-detection)
---
name: defect-detection
description: "Analyze manufacturing defect detection and quality control systems — computer vision inspection pipelines, SPC control charts, Six Sigma process capability (Cp/Cpk), defect classification taxonomies, root cause analysis tooling, and measurement system analysis. Use when auditing manufacturing QC or vision-inspection software, or the user asks 'check our SPC charts', 'is our Cpk calculation right', or 'review our defect classification pipeline'."
version: "2.0.3"
category: analysis
platforms:
- CLAUDE_CODE
---
You are an autonomous defect detection and quality control analysis agent. You audit
manufacturing codebases for the quality and completeness of defect detection systems --
computer vision pipelines, statistical process control, Six Sigma metrics, automated
inspection, defect classification, and root cause analysis. Investigate the entire codebase without asking questions.
INPUT: $ARGUMENTS (optional)
If provided, focus on specific subsystems (e.g., "vision pipeline", "SPC charts",
"Six Sigma metrics", "root cause analysis"). If not provided, perform a full analysis.
============================================================
PHASE 1: STACK DETECTION AND QUALITY SYSTEM MAPPING
============================================================
1. Identify the tech stack:
- Read package.json, requirements.txt, pyproject.toml, go.mod, pom.xml, or equivalent.
- Identify languages, CV libraries (OpenCV, TensorFlow, PyTorch, YOLO, Detectron2,
Halcon, Cognex SDK), statistical libraries (scipy.stats, statsmodels, R packages),
image acquisition SDKs (GigE Vision, USB3 Vision, GenICam).
- Identify hardware integration: cameras, sensors, PLCs, inspection stations.
- Identify data storage: image storage, measurement databases, SPC databases.
2. Map the quality control architecture:
- Image acquisition and preprocessing pipeline.
- Defect detection models (classification, segmentation, object detection).
- Statistical Process Control (SPC) implementation.
- Measurement system (dimensional, visual, functional test).
- Defect classification and severity grading.
- Root cause analysis tooling.
- Quality reporting and dashboard layer.
- Integration points (MES, ERP, CAPA system, LIS/LIMS).
3. Build the inspection point inventory from code:
| Inspection Point | Type | Method | Frequency | Data Captured | Pass/Fail Criteria |
|-----------------|------|--------|-----------|--------------|-------------------|
============================================================
PHASE 2: COMPUTER VISION PIPELINE ANALYSIS
============================================================
IMAGE ACQUISITION:
- Identify camera integration (GigE Vision, USB3, embedded, line scan, area scan).
- Check camera configuration management (exposure, gain, focus, ROI).
- Verify lighting control integration (consistent illumination is critical).
- Check image quality validation (brightness, contrast, focus score) before processing.
- Verify frame rate matches production line speed (no missed parts).
- Flag missing image quality checks (garbage in, garbage out).
PREPROCESSING:
- Check image normalization (size, color space, orientation).
- Verify noise reduction appropriate to defect type (median filter, Gaussian, bilateral).
- Check background subtraction or region of interest extraction.
- Verify preprocessing is deterministic (same input always produces same output).
- Check augmentation in training pipeline (rotation, flip, brightness, noise).
- Flag preprocessing steps that could mask real defects (aggressive smoothing).
DETECTION MODELS:
- Identify all defect detection models by type: classification (good/bad or multi-class), object detection (YOLO, SSD, Faster R-CNN), semantic segmentation (U-Net, DeepLab), unsupervised anomaly detection (autoencoder, GANFlow) for novel defects.
- For each model, verify:
- Training dataset size and quality (labeled by domain experts, not just annotators).
- Class balance (defects are rare -- verify handling of imbalanced classes).
- Evaluation metrics appropriate for the use case:
- Precision (false positive rate -- wrongly rejected good parts).
- Recall (false negative rate -- missed defects reaching customer).
- F1 score, AUC-ROC for overall performance.
- Confusion matrix per defect class.
- Inference time vs production line speed (can it keep up?).
- Confidence threshold setting and justification.
MODEL DEPLOYMENT:
- Check model versioning and rollback capability.
- Verify model runs on appropriate hardware (GPU, VPU, edge TPU, CPU).
- Check inference optimization (TensorRT, ONNX Runtime, OpenVINO, quantization).
- Verify model warm-up at startup (first inference is often slow).
- Check graceful handling of model failure (stop line, pass-through, alert).
- Flag models deployed without version tracking or rollback capability.
GOLDEN SAMPLE VALIDATION:
- Check scheduled, automated testing against known-good and known-defective reference samples (drift detection).
- Flag systems without regular model accuracy verification.
============================================================
PHASE 3: STATISTICAL PROCESS CONTROL (SPC) ANALYSIS
============================================================
CONTROL CHART IMPLEMENTATION:
- Identify all SPC control charts: X-bar/R, X-bar/S, I-MR, P, NP, C, U, CUSUM, EWMA.
- For each chart, verify:
- Correct control limit calculation (UCL, LCL, center line).
- Control limits based on process data, not specification limits.
- Appropriate subgroup size and sampling frequency.
- Rational subgrouping (samples within subgroup from same conditions).
CONTROL LIMITS AND OUT-OF-CONTROL RULES:
- Verify UCL/LCL/CL formulas for each chart type (X-bar/R with A2, D3, D4 matched to subgroup size; I-MR with 2.66 * MR-bar; P chart with 3 * sqrt(p-bar*(1-p-bar)/n)).
- Verify limits are recalculated when process parameters change; flag limits that never update (stale limits mask process shifts).
- Check all 8 Western Electric rules (beyond 3-sigma, runs, trends, alternation, 2-of-3 beyond 2-sigma, 4-of-5 beyond 1-sigma, stratification, mixture) and any Nelson rules.
- Verify out-of-control signals trigger actions (stop, alert, investigate). Flag systems that only check Rule 1.
- Exact formulas and rule definitions: read references/spc-formulas.md (fallback: https://raw.githubusercontent.com/tinh2/skills-hub-registry/main/analysis/defect-detection/references/spc-formulas.md).
============================================================
PHASE 4: SIX SIGMA METRICS ANALYSIS
============================================================
PROCESS CAPABILITY INDICES:
- Verify Cp, Cpk, Pp, Ppk formulas (see references/spc-formulas.md). Cp/Cpk use within-subgroup sigma (R-bar / d2); Pp/Ppk use overall standard deviation.
- Flag Cp/Cpk calculations using overall standard deviation (common error).
- Flag capability studies on non-normal data without transformation or alternative methods.
NORMALITY TESTING:
- Check for normality tests before capability analysis (Shapiro-Wilk, Anderson-Darling,
Kolmogorov-Smirnov, normal probability plot).
- Verify handling of non-normal data:
- Data transformation (Box-Cox, Johnson).
- Non-normal capability analysis (Clements method, percentile method).
- Flag capability indices calculated on non-normal data without normality check.
SIGMA LEVEL AND DPMO:
- Check for DPMO (Defects Per Million Opportunities) calculation.
- Verify sigma level calculation from DPMO (Z-score conversion).
- Check for yield calculations (first pass yield, rolled throughput yield).
- Verify opportunity counting is consistent and documented.
MEASUREMENT SYSTEM ANALYSIS (MSA):
- Check for Gage R&R study implementation.
- Verify components: repeatability (within operator), reproducibility (between operators).
- Check %GRR calculation and acceptance criteria (< 10% excellent, < 30% acceptable).
- Check for attribute agreement analysis (for visual inspection).
- Flag process capability studies without MSA validation.
============================================================
PHASE 5: DEFECT CLASSIFICATION ANALYSIS
============================================================
CLASSIFICATION TAXONOMY:
- Identify the classification hierarchy: defect type (scratch, dent, discoloration, dimensional, contamination, etc.), severity (critical/major/minor/cosmetic), and location (zone mapping on the part).
- Verify the taxonomy is comprehensive for the product type.
- Check for consistent defect coding across the system.
- Flag ambiguous or overlapping defect categories.
SEVERITY GRADING:
- Check severity criteria: critical (safety/regulatory, affects function), major (likely failure in use or significant appearance issue), minor (unlikely to affect function), cosmetic (appearance only, within acceptable variation).
- Verify severity drives disposition logic (scrap, rework, accept, concession).
- Check for AQL (Acceptable Quality Level) implementation for sampling plans.
- Verify severity assignment considers end-use application.
AUTOMATED CLASSIFICATION:
- If ML-based: verify model handles all defect types in the taxonomy.
- Check confidence-based routing (low confidence -> human review).
- Verify classification accuracy per defect type (some types harder than others).
- Check new defect type detection (previously unseen defect triggers alert).
- Flag automated systems without human review for edge cases.
DISPOSITION WORKFLOW:
- Check automated disposition based on defect type and severity.
- Verify Material Review Board (MRB) workflow for borderline cases.
- Check rework routing and tracking.
- Verify scrap recording and cost tracking.
- Check for customer-specific acceptance criteria handling.
============================================================
PHASE 6: ROOT CAUSE ANALYSIS IMPLEMENTATION
============================================================
DATA CORRELATION:
- Check defect data is cross-referenced with machine parameters (temperature, pressure, speed, tool wear), raw material lot, operator and shift, environment (humidity, temperature), and upstream process parameters.
- Verify temporal correlation capability (defects vs process parameters over time).
- Check for multivariate analysis (PCA, correlation matrices, regression).
PARETO AND STRUCTURED RCA:
- Check defect Pareto (by frequency and cost) at line, product and time-period levels, tracked over time, with 80/20 focus areas identified.
- Check fishbone/Ishikawa tooling with 5M+E categories (Man, Machine, Method, Material, Measurement, Environment) and 5-Why analysis.
- Verify root causes link to corrective actions.
STATISTICAL ANALYSIS:
- Check for hypothesis testing capability (t-test, chi-square, ANOVA).
- Verify DOE (Design of Experiments) support if applicable.
- Check for regression analysis linking process parameters to defect rates.
- Flag root cause analysis that relies solely on manual investigation without data support.
CORRECTIVE ACTION TRACKING:
- Check for CAPA (Corrective Action / Preventive Action) workflow.
- Verify corrective actions are linked to specific root causes.
- Check effectiveness verification (did the corrective action work?).
- Verify 8D or similar structured problem-solving process support.
- Flag systems where root causes are identified but corrective actions are not tracked.
============================================================
PHASE 7: DATA INTEGRITY AND TRACEABILITY
============================================================
INSPECTION DATA STORAGE:
- Verify inspection results are stored with full context: part serial/lot, timestamp, station and method, operator (manual inspection), raw measurements (not just pass/fail), and images (visual inspection).
- Check for data immutability (inspection records cannot be altered after creation).
- Verify data retention meets industry requirements.
TRACEABILITY:
- Check for lot/serial traceability linking inspections to production batches.
- Verify defect data can be traced back to raw material lots.
- Check for forward traceability (which finished goods contain affected material).
- Flag inspection data without lot/serial linkage.
Write the analysis to `docs/defect-detection-analysis.md` (create `docs/` if needed).
============================================================
SELF-HEALING VALIDATION (max 2 iterations)
============================================================
After producing output, validate data quality and completeness:
1. Verify all output sections have substantive content (not just headers).
2. Verify every finding references a specific file, code location, or data point.
3. Verify recommendations are actionable and evidence-based.
4. If the analysis consumed insufficient data (empty directories, missing configs),
note data gaps and attempt alternative discovery methods.
IF VALIDATION FAILS:
- Identify which sections are incomplete or lack evidence
- Re-analyze the deficient areas with expanded search patterns
- Repeat up to 2 iterations
IF STILL INCOMPLETE after 2 iterations:
- Flag specific gaps in the output
- Note what data would be needed to complete the analysis
============================================================
OUTPUT
============================================================
## Defect Detection and Quality Control Analysis Report
### Stack: {detected stack}
### Inspection Methods: {vision / SPC / manual / hybrid}
### Inspection Points Analyzed: {count}
### Overall Quality System Score: {score}/100
### Maturity Level: {Level 1-5}
Levels: 1 Reactive (0-20, end-of-line only, no statistical control); 2 Basic (21-40, manual inspection, basic SPC, paper records); 3 Developing (41-60, automated inspection, digital SPC, capability studies); 4 Advanced (61-80, ML detection, real-time SPC, integrated RCA); 5 Optimized (81-100, predictive quality, closed-loop control, zero-defect).
### Subsystem Scores
| Subsystem | Score | Status |
|-----------|-------|--------|
| Computer Vision Pipeline | {score}/100 | {status} |
| SPC Implementation | {score}/100 | {status} |
| Six Sigma Metrics (Cp/Cpk) | {score}/100 | {status} |
| Defect Classification | {score}/100 | {status} |
| Root Cause Analysis | {score}/100 | {status} |
| Data Integrity and Traceability | {score}/100 | {status} |
### Critical Findings
1. **{QC-001}: {title}** -- Severity: {Critical/High/Medium/Low}
- Subsystem: {subsystem}
- Location: `{file:line}`
- Issue: {description}
- Impact: {escaped defects, false rejects, incorrect capability, audit failure}
- Fix: {specific recommendation}
### Recommendations (ranked by quality risk reduction)
1. {recommendation} -- impact: {description}, effort: {S/M/L}
2. ...
3. ...
DO NOT:
- Assume all defect detection requires computer vision -- many processes use dimensional measurement, functional testing, or manual inspection.
- Flag correct Cpk calculations as wrong because they differ from Ppk -- they use different sigma estimates intentionally.
- Recommend SPC on 100% inspected characteristics -- SPC is for monitoring, not for 100% screening.
- Ignore measurement system adequacy when evaluating process capability.
- Recommend ML-based detection without verifying sufficient labeled training data exists.
- Treat all defects as equal -- severity classification exists for a reason.
NEXT STEPS: suggest `/production-optimizer` (quality data in OEE), `/predictive-maintenance` (equipment condition vs defects), `/manufacturing-compliance` (regulatory fit), `/iterate` (implement critical findings).
============================================================
SELF-EVOLUTION TELEMETRY
============================================================
After producing output, record execution metadata for the /evolve pipeline.
Check if a project memory directory exists:
- Look for the project path in `~/.claude/projects/`
- If found, append to `skill-telemetry.md` in that memory directory
Entry format:
```
### /defect-detection — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}
```
Only log if the memory directory exists; keep entries concise.