Sub topic 7
Source inspection: checking conditions before the error happens
This chapter assumes you know what a defect is, how an error differs from a defect, and the difference between preventing an error and detecting one. It also assumes you can read short Python snippets. The software examples are the only code in the chapter.
What source inspection is
Source inspection checks the conditions that make an error possible, before the error happens. It does not check the product after the error has produced a defect. Shigeo Shingo described it as one of the three kinds of inspection, and he ranked it highest because it works on the cause.
The three kinds differ in when they look and what they do about a problem:
| Kind | What it checks | When | Result |
|---|---|---|---|
| Judgment inspection | The finished item | After the process | Finds defects, so scrap and rework already exist |
| Informative inspection | The item or process, then feeds back | After a step, or in the next steps | Faster correction, but defects still occur |
| Source inspection | The conditions that cause errors | Before the step runs | The error is stopped, so no defect is made |
The goal is what Shingo called zero quality control: a process that cannot produce a defect, so it needs no sorting of good from bad. In practice, you rarely reach zero. You move the check as far upstream as you can.
The source: conditions, not products
The "source" is the set of conditions that must hold for a step to be done correctly. Examples are the right part in the fixture, the right tool selected, the right value entered, and the previous step finished. If one of these conditions is false, an error is likely.
Source inspection asks one question before each step: are the conditions for this step correct right now? If the answer is no, the step does not run, or the operator is stopped before starting it.
Compare two ways to handle a missing washer in an assembly:
- Judgment inspection: an inspector at the end of the line finds a unit with no washer. The unit is reworked or scrapped.
- Source inspection: a sensor at the station checks that a washer is present in the feeder before the fastening step. If it is empty, the fixture will not clamp.
In the second case, no defective unit exists. The error (starting without a washer) was blocked at its source.
Source inspection is a prevention approach
Source inspection belongs to the prevention side of the prevention versus detection split. It usually uses a control device, meaning one that shuts the process down or blocks the next step. A warning device (a light or a buzzer) can also check at the source, but a warning leaves the decision to the operator. A control device does not.
Source checks combine well with the three Shingo methods you met earlier:
- Contact method: a sensor or a physical shape checks the item. A part with a missing hole will not seat in a jig.
- Fixed-value method: the process counts something, such as the number of fasteners used, and blocks completion if the count is wrong.
- Motion-step method: the process checks that the required prior steps were done in order, and blocks the next step if they were not.
The method says how you check. Source inspection says when you check: before the error can occur.
Choosing what to check at the source
A good source check targets a condition that is both important and checkable. Use these questions:
- Which condition, if wrong, leads to the error? Use the root cause you found, not a guess.
- Can the condition be tested before the step starts, cheaply and reliably?
- Can the process refuse to continue if the test fails?
- Does the check measure the real condition, or a stand-in for it?
The fourth question matters more than it seems. A sensor that detects "a container is present" does not detect "the right container is present". If the root cause is the wrong container, the check must tell containers apart. Otherwise it gives a pass that means nothing.
Source inspection in software
Software is a good place to apply source inspection because checks cost little and run every time. The goal is the same: test the conditions before the action, and refuse to act if they are wrong.
Checking the state before a change
The first code example guards against skipped or backward steps in an order's life cycle. The check runs before the status changes, so an invalid status never exists in the data.
from enum import Enum
class OrderStatus(Enum):
DRAFT = "draft"
PAID = "paid"
SHIPPED = "shipped"
ALLOWED_TRANSITIONS = {
OrderStatus.DRAFT: {OrderStatus.PAID},
OrderStatus.PAID: {OrderStatus.SHIPPED},
OrderStatus.SHIPPED: set(),
}
def change_status(current: OrderStatus, new: OrderStatus) -> OrderStatus:
if new not in ALLOWED_TRANSITIONS[current]:
raise ValueError(f"Cannot move from {current.value} to {new.value}")
return new
status = OrderStatus.DRAFT
status = change_status(status, OrderStatus.PAID) # allowed
# change_status(status, OrderStatus.DRAFT) would raise ValueErrorThis is a source check on a motion-step condition. The condition is "the order is in a state from which this move is allowed". The enum also removes a whole class of wrong values, since a status such as "shiped" cannot be built.
Checking the inputs before the action
The second example checks the inputs of a money transfer before any money moves.
def transfer(*, source_account: str, destination_account: str, amount_cents: int) -> str:
if source_account == destination_account:
raise ValueError("Source and destination must differ")
if amount_cents <= 0:
raise ValueError("Amount must be positive")
return f"Moved {amount_cents} cents from {source_account} to {destination_account}"
# Keyword-only arguments make a swapped-argument slip visible at the call site.
transfer(source_account="A-100", destination_account="B-200", amount_cents=2500)
# transfer("A-100", "B-200", 2500) raises TypeErrorThe bare * makes callers name each argument, so two strings cannot be swapped by position without the call looking wrong. The two if checks reject inputs that cannot be valid. Both run before the function does any work.
Checking the person's attention
The third example checks a condition about the operator: whether they have read the target.
def delete_environment(name: str, confirm_name: str) -> str:
if confirm_name != name:
raise ValueError("Confirmation does not match the environment name; nothing was deleted")
return f"Deleted {name}"
delete_environment("staging", "staging") # proceeds
# delete_environment("production", "staging") raises ValueErrorA simple "Are you sure? (y/n)" fails because people press y out of habit. Retyping the name forces a motion that cannot be done without looking at the target. The check runs before the deletion, so the wrong environment survives.
Edge cases and limits
Source inspection is strong, but it has limits you should plan for.
- It only covers conditions you thought of. If the true root cause is not on your list, the check passes while the error still happens. Tie each check to a root cause analysis, not to a hunch.
- A condition can change after the check. A part can be removed after the sensor read it. Where there is a gap in time between check and action, shorten the gap or check again at the step.
- A check on a stand-in can pass while the real condition is wrong, as with the container example above.
- A blocking check that fires too often gets bypassed. If operators meet false stops every shift, they will tape over the sensor. Measure the false-stop rate during trials.
- Source checks do not remove the need for other controls. Keep a downstream check for errors you could not foresee, and treat it as a backup, not the main defense.
Comparing the options
When you design a fix, you can often place the check at several points. Compare them on the same terms.
| Check placed | Defect made? | Cost of the problem | Typical device |
|---|---|---|---|
| Final inspection | Yes | Scrap or rework | Inspector, test stand |
| Right after the step | Yes, but caught fast | Small rework | Gauge, alarm |
| Before the step (source) | No | A stopped step | Sensor interlock, validation, state check |
Move the check to the earliest point where you can test the condition reliably. Stop moving it earlier when the test becomes costly or unreliable. A check at the very start of a long chain of steps may be too far from the step it protects, because conditions can drift in between.
A short working method
- Name the error and find its root cause.
- List the conditions that must be true before the step.
- Pick the condition that the root cause points to.
- Choose a method (contact, fixed-value, or motion-step) that tests it.
- Make the step refuse to run when the test fails.
- Try to defeat the check. Fix any easy route around it.
Exercise
A packing station sometimes ships a box with no instruction leaflet. An inspector weighs every packed box and rejects the light ones. Describe a source inspection for this problem, say which Shingo method it uses, and explain why it ranks above the weighing.
Show answer
Place a sensor or a slot at the leaflet dispenser so the box sealer will not close unless a leaflet was taken for this box (a motion-step check on the prior step) or the tray holds one leaflet for each box (a fixed-value check). The check runs before the sealing step, so no leaflet-less box is made. The weighing is a judgment inspection that finds the defect after it exists, so it still produces rework and can miss light-but-wrong boxes. The source check stops the error, so there is nothing to find.
Exercise
A software team replaces the prompt "Delete this database? (y/n)" with a prompt that asks the user to type the database name. Which kind of check is this, and what condition does it test at the source?
Show answer
It is a source check built on the motion-step idea. It tests that the operator has identified the target before the deletion runs. Typing the name needs attention to the target, which a habitual "y" does not, and the delete function refuses to run when the typed name does not match.