Poka-Yoke Mistake-Proofing

Poka-Yoke Mistake-Proofing

Helps design and audit code so misuse cannot be expressed, finding footguns and closing whole classes of recurring bugs rather than single cases.

Skill files6 files

references/

scripts/

SKILL.md204 lines
1
---
2
name: poka-yoke
3
description: 'Mistake-proof code so misuse cannot be expressed, rather than warning against it. Use when designing an interface, schema, or state machine and the user wants it hard to get wrong ("make invalid states unrepresentable", "so callers cannot screw it up", "type-safe API", "pit of success"); when auditing existing code for footguns ("what could bite us here", "what is easy to misuse", "poka-yoke this repo", "review this diff for ways to get it wrong"); or when a bug has recurred and the fix must close the class rather than the case ("make sure this never happens again", "this is the third time"). Especially for money, auth, permissions, deletion, migrations, and pipelines where failure is silent. Classifies every finding by what happens when the mistake occurs and how the device notices, which is what keeps it from collapsing into generic code review.'
4
license: MIT
5
compatibility: 'Cross-platform. The bundled scanner needs Python 3.9+ and no third-party packages. Everything else is language-agnostic guidance; worked examples are TypeScript, Python, Go, Rust and SQL.'
6
metadata:
7
version: '1.0'
8
source: https://github.com/rainmanjam/poka-yoke
9
---
10
11
# Poka-Yoke: Make the Mistake Unsayable
12
13
**People will always make mistakes. That is not the problem worth solving. The problem is
14
letting a mistake become a defect.**
15
16
Shigeo Shingo, a Japanese industrial engineer, worked this out on a switch assembly line in
17
1961. Workers kept forgetting a spring. The fix was not a reminder: the job was split so the
18
worker first laid both springs in a dish, then fitted them from the dish. A spring left over
19
was the error announcing itself, before the unit could move on.
20
21
The dish is a device. "Please remember the spring" is not.
22
23
## The line that does most of the work
24
25
> A comment, a docstring, a wiki page, a review checklist, or a line in an instructions file
26
> saying "don't do X" is **not** a poka-yoke. It is training, and training degrades. A device
27
> does not. If your fix relies on someone remembering something, keep going.
28
29
This applies to your own instructions too. A rule written into a config file competes for
30
attention with every other rule there and loses a little more as the file grows. A check that
31
fails the build does not.
32
33
## What this changes about the output
34
35
Given a design, models will readily list what to fix. They rarely state what the fix makes
36
*impossible*, and that is the difference between advice you agree with and a constraint you
37
can rely on. That habit is most of what this skill is for.
38
39
The other half is refusing to accept a non-device as a fix. "Add validation", "be careful with
40
this function", "document the invariant" are all rung zero. Each has a real device behind it,
41
and naming that device is the work.
42
43
## Axis 1: what happens when the mistake occurs
44
45
Rank every finding on this ladder, and say which rung the current code sits on and which rung
46
your fix reaches.
47
48
| Rung | Name | Meaning |
49
|---|---|---|
50
| 1 | **Control** | The wrong action cannot be performed. Type error, database constraint, missing permission. |
51
| 2 | **Warning** | It is possible, but announces itself as it happens. A linter, a runtime assertion, a confirmation you cannot skip. |
52
| 3 | **Detection** | It happens, and you find out afterwards. Tests, logging, monitoring, code review. |
53
| 0 | **rung zero** | Telling people to be careful. Docs, comments, "please remember to". |
54
55
Detection is not failure; sometimes it is all that is available. But a plan that stops at
56
Detection should say so, rather than presenting it as prevention.
57
58
## Axis 2: how the device notices
59
60
Shingo's three inspection lenses. They are a checklist for *finding* hazards, not decoration:
61
62
- **Contact** — can the wrong thing physically fit? Two adjacent parameters of the same type can be swapped silently. A `string` that should be one of four values. Money as a float.
63
- **Fixed-value** — is the set complete? A switch with no exhaustiveness check. A config where a missing key silently means "off". An enum handled in three of five places.
64
- **Motion-step** — is the order right, and did every step happen? A two-phase write with no transaction. A retry with no idempotency key. A resource acquired on one path and released on another.
65
66
## Inspect at the source
67
68
The cheapest place to catch a mistake is where it is made, not where it surfaces. A validation
69
that runs three layers below the input has already let the bad value travel, and the stack
70
trace will point at the wrong module. Push the check to the boundary the value crosses.
71
72
## Designing something new
73
74
Mistake-proofing is cheapest before the code has callers. Once it has them, every device is a
75
migration; before it has them, a device is free.
76
77
Work from the call site. A signature that reads fine in isolation often reads terribly where
78
it is used:
79
80
```python
81
# the mistake is expressible: nothing stops refunding an order that was never paid
82
def refund(order: dict) -> Refund:
83
return payments.refund(order["payment_id"])
84
85
# the mistake is no longer expressible
86
def refund(order: PaidOrder) -> Refund: ...
87
```
88
89
The moves, roughly in order of how often they apply:
90
91
**Make invalid states unrepresentable.** A bag of optional fields where only certain
92
combinations are legal becomes a discriminated union where the illegal ones cannot be
93
constructed.
94
95
**Parse, don't validate.** Convert unstructured input into a type that carries proof at the
96
boundary, once, rather than re-checking the same string in nine places.
97
98
**Distinguish concepts that share a primitive.** `transfer(from: str, to: str)` accepts its
99
arguments transposed. Distinct types for the two concepts, or keyword-only parameters, make the
100
transposition a compile error.
101
102
**Encode the order.** When calls must happen in sequence, let each step return the type the
103
next step requires, so the wrong order does not typecheck.
104
105
**Make the destructive path narrower than the safe one.** A required, non-defaulting argument
106
for the scope of a delete. A default that means "nothing" rather than "everything".
107
108
Close by naming what the design now makes impossible, and, just as importantly, **what you
109
deliberately left possible and why**. A design whose limits are unstated will be trusted past
110
them.
111
112
## Auditing code that already exists
113
114
You are not looking for bugs. A bug is a mistake that already happened. You are looking for
115
**mistakes that are available**: places where doing the wrong thing is easy, silent, and looks
116
correct.
117
118
Run the bundled scanner first for the textually detectable shapes, then read for the ones no
119
scanner can see:
120
121
```bash
122
python3 scripts/detect_hazards.py --paths . # whole tree
123
python3 scripts/detect_hazards.py --staged # pre-commit
124
python3 scripts/detect_hazards.py --diff --json # CI, exits non-zero on findings
125
python3 scripts/detect_hazards.py --severity high
126
```
127
128
No dependencies, so it runs in CI and in a pre-commit hook without an install step. It reports
129
what it scanned: a scan of zero files exits non-zero rather than reporting a clean bill of
130
health, because an all-clear you got by typo is worse than no check.
131
132
Rank findings by **blast radius times ease of the mistake**. An unchecked value reaching a
133
write, a delete, a payment or an auth decision outranks one that can only produce a clean
134
crash. For each finding, state: where it is, what the mistake is, what the consequence is, what
135
device exists today, what device would close it, and which rung that reaches.
136
137
`references/hazard-catalog.md` is the taxonomy of shapes with their IDs and devices.
138
Language-specific patterns are in `references/lang-python.md`, `references/lang-typescript.md`
139
and `references/lang-rust-go.md`.
140
141
## After an incident
142
143
Separate three things that get conflated, because the fix belongs to the third:
144
145
- **Defect** — what the user experienced.
146
- **Mistake** — the specific wrong action someone took.
147
- **Hazard** — the property of the system that made that mistake available.
148
149
Fixing the mistake fixes one case. Fixing the hazard fixes the class. Then **sweep**: the same
150
shape almost certainly exists elsewhere, and finding the second and third instance is the
151
difference between a patch and a lesson.
152
153
Attribute cause to the system rather than to a person. Not primarily for kindness: "they made a
154
mistake" is a complete-sounding explanation that predicts nothing and prevents nothing, and it
155
ends the investigation early.
156
157
## What good output looks like
158
159
- **Anchored to lines.** `orders.py:142, apply_discount` is reviewable; "the discount logic" is not.
160
- **Ranked, with the ranking visible**, so a reader who stops halfway has still covered the ones that matter.
161
- **A named device per finding**, not "add validation".
162
- **The rung stated**, before and after.
163
- **The limits stated.** What the fix does not cover is the part readers most need and most often do not get.
164
- **Sized honestly.** Three findings that matter beat eleven padded to a round number.
165
166
## What to avoid
167
168
**Accepting rung zero as a fix.** If the proposal is a comment, a doc, or a convention, the
169
work is not finished.
170
171
**Devices nobody can bypass being confused with devices nobody does bypass.** A pre-commit hook
172
is skippable with `--no-verify`; it needs CI behind it to be a real gate. Say which one you are
173
proposing.
174
175
**Over-fitting to one incident.** Machinery that prevents one specific failure must itself be
176
understood and maintained. Ask whether the shape is common enough to justify it.
177
178
**Treating monitoring as prevention.** Detection lowers the cost of a failure; it does not lower
179
the likelihood. Both are worth having, and conflating them means the likelihood never gets
180
addressed.
181
182
## Evidence, and its limits
183
184
This method was benchmarked at 591 blind-graded runs across six model families, scored against
185
assertions written before the runs by a grader that never saw which configuration produced a
186
response. The behaviour it most reliably changes is stating what a design forecloses: **45% of
187
responses did that unprompted, 80% with the method applied**, across 132 graded verdicts.
188
189
That average conceals where the effect lives. Asked squarely to design an interface, models
190
already do it 77% of the time; the skills add eleven points. The large gains are in tasks
191
where nobody asked for a design review — writing an endpoint goes 14% to 79%, shipping an
192
agent feature 33% to 83%, building a form 29% to 64%.
193
194
Stated honestly, because the limits matter: every run was the first turn of a fresh session, so
195
this measures the ceiling rather than what survives a long working session. The comparison was
196
against no methodology at all, not against a different one, so it does not establish that
197
*this* method is what produced the gain. And the method costs something measurable: responses
198
became somewhat worse at spotting the specific defect already on the page while becoming better
199
at changing the shape that allowed it. If you want the bug in front of you found, use a
200
reviewer. If you want that class of bug to stop being expressible, use this.
201
202
Raw runs, the harness and the assertion checklists are at
203
<https://github.com/rainmanjam/poka-yoke>.
204

© awesome-copilot contributors · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…