Constraints: Limiting Actions to Prevent Errors skill

Constraints are design elements that limit the possible actions a user can take.

by wondelai·MIT license·★ 2,235 Stars on the repo·GitHub ↗

Use now

Files of Constraints: Limiting Actions to Prevent Errors

wondelai/main1 file
constraints.md
Show the full text257 lines

Constraints: Limiting Actions to Prevent Errors

Constraints are design elements that limit the possible actions a user can take. Used well, they make errors impossible or improbable. The underlying principle is simple: instead of telling users what not to do, make the wrong action physically, logically, or semantically impossible. Every constraint added is one fewer error the user can make.

Four Constraint Types

Physical Constraints

Physical constraints use shape, size, or material properties to restrict actions.

Constraint How It Works Example
Shape exclusion Parts only fit one way USB-A plug has a correct orientation; USB-C fits both ways
Size limitation Object is too large/small for wrong use A large plug cannot fit a small socket
Material resistance Force required prevents accidental activation Childproof medicine bottle requires push-and-twist
Barrier Physical blockage prevents access Guardrails prevent cars from leaving the road

Digital equivalent: Input masks, character limits, file type restrictions, and minimum/maximum values.

Cultural Constraints

Cultural constraints rely on shared social conventions and learned norms to guide behavior.

Constraint How It Works Example
Social norms Expected behavior in context Whispering in a library, facing forward in an elevator
Color conventions Shared color meanings Red for stop/danger, green for go/safe
Positional conventions Expected placement of elements OK/Cancel button order (platform-dependent)
Interaction conventions Learned digital behaviors Double-click to open, single-click to select

Design implication: Cultural constraints are powerful but invisible. Violating them causes confusion even when the system technically works.

Semantic Constraints

Semantic constraints use the meaning of a situation to limit the set of possible actions.

Constraint How It Works Example
Contextual meaning Meaning restricts logical placement A rearview mirror only makes sense facing the rear
Role meaning Knowledge of purpose limits actions A windshield is obviously not a door
Temporal meaning Timing restricts when actions make sense Cannot review an order before adding items

Digital equivalent: Contextual menus that show only relevant actions, conditional fields that appear based on prior selections.

Logical Constraints

Logical constraints use reasoning to limit what is possible through exclusion.

Constraint How It Works Example
Process of elimination Only one option remains Last puzzle piece can only go in the remaining hole
Mutual exclusion Choosing A makes B impossible Radio buttons: selecting one deselects others
Dependency chains Step B requires step A Cannot format text before selecting it
Completeness check All parts must be present Form cannot submit until all required fields are filled

Digital Constraint Implementations

Input Validation as Constraint
Validation Type What It Constrains Implementation
Type restriction Only numbers, only letters, specific format input type="email", type="tel", regex patterns
Range restriction Minimum and maximum values min="0" max="100", date ranges, slider bounds
Length restriction Character count maxlength="280", with visible counter
Format restriction Specific pattern required Input mask for phone: (__) -
Enum restriction Only predefined options allowed Dropdown, radio buttons, autocomplete with fixed list
Real-time validation Invalid input rejected as typed Inline error showing before form submission
Best Practices for Input Validation
  • Prefer prevention over detection: use a date picker instead of validating a typed date.
  • Validate in real time, not only on submit. Show inline feedback as the user types.
  • When rejecting input, explain what is expected: "Phone number must be 10 digits" not "Invalid input."
  • Accept flexible formats and normalize internally: "1234567890", "(123) 456-7890", and "123-456-7890" should all be accepted for a phone number.
Progressive Disclosure as Constraint

Progressive disclosure constrains what users see and interact with, reducing cognitive load and preventing premature actions.

Pattern What It Constrains Example
Collapsed sections Hides advanced options until requested "Advanced settings" expandable panel
Wizard / stepper Shows only current step Multi-step checkout flow
Conditional fields Shows fields only when relevant "Other" text field appears only when "Other" is selected
Role-based visibility Shows features based on permissions Admin panel visible only to admin users
Contextual menus Shows only actions relevant to the selected item Right-click menu changes based on element type
Disabled States and Forced Sequences

Disabled states constrain users by making actions visually present but temporarily unavailable.

Pattern When to Use How to Implement
Disabled button Required precondition not met Gray out button, add tooltip explaining why
Locked wizard step Prior steps incomplete Show step indicator but prevent skipping ahead
Conditional enable Depends on another field's value Enable "Confirm" only after checkbox is checked
Time-gated action Action requires waiting period "You can send again in 30 seconds" with countdown
Auth-gated action Requires login or elevated permissions Show the action but redirect to login on click

Critical rule for disabled states: Always explain why the action is disabled. A disabled button with no explanation is a constraint that creates frustration rather than guiding users.

Implementation User Experience
Disabled button, no explanation "Why can't I click this? Is it broken?"
Disabled button with tooltip "I see -- I need to fill in the required fields first."
Disabled button with inline helper text "Fill in all required fields to enable submission."
Undo/Redo as Error Recovery Constraint

Undo/redo does not prevent errors, but it constrains the impact of errors by making them reversible.

Pattern Implementation Example
Immediate undo Toast notification with "Undo" link Gmail "Message sent. Undo"
Action history List of recent actions with rollback Google Docs version history
Soft delete Items move to trash, not permanently deleted Recycle bin, 30-day retention
Autosave with versions Every change is saved and reversible Google Docs, Figma auto-save
Confirmation dialog "Are you sure?" before destructive action Delete account confirmation
When to Use Confirmation Dialogs

Confirmation dialogs are appropriate only for:

  • Irreversible actions (delete account, send broadcast email)
  • High-consequence actions (charge credit card, publish to production)
  • Unusual actions (something the user does rarely and might have triggered accidentally)

They are NOT appropriate for:

  • Routine actions (saving a document, closing a tab)
  • Actions that are easily reversible (moving an item, changing a setting)
  • Frequent operations (every dialog slows the user down and trains them to click "OK" without reading)

Constraint Design Patterns by Use Case

E-Commerce Checkout
Constraint Type Purpose
Cannot proceed to payment without shipping address Logical (forced sequence) Prevents incomplete orders
Credit card field accepts only digits with auto-formatting Physical (input mask) Prevents format errors
"Place Order" disabled until terms checkbox is checked Logical (dependency) Ensures legal compliance
Quantity selector with min=1, max=99 Physical (range) Prevents zero or absurd quantities
Address autocomplete from verified database Semantic (constrained options) Prevents undeliverable addresses
User Registration
Constraint Type Purpose
Password strength meter with minimum requirements Physical (validation) Prevents weak passwords
Email format validation Physical (format) Prevents invalid email addresses
Username uniqueness check (real-time) Logical (exclusion) Prevents duplicate accounts
Age gate with date picker Semantic (contextual) Prevents underage registration
CAPTCHA before submission Cultural (convention) + Logical Prevents automated abuse
Content Management
Constraint Type Purpose
Draft / Published / Archived states with transitions Logical (forced sequence) Content must be reviewed before publishing
Character limits on titles and descriptions Physical (length) Prevents layout-breaking content
Image upload restricted to specific formats and sizes Physical (type + size) Prevents unsupported media
Scheduled publish date must be in the future Semantic (temporal) Prevents backdated publishing
Role-based editing permissions Cultural (authority) + Logical Prevents unauthorized changes

When Constraints Help vs. Frustrate

Constraints That Help
Scenario Why It Helps
Date picker instead of free text Users cannot enter an invalid date format
Disabled "Next" until required fields are complete Users cannot skip required information
Autocomplete for city/state from zip code Reduces typing and prevents mismatched data
File upload limit with clear message Prevents timeout errors on oversized files
Character counter approaching limit Users adjust their content proactively
Constraints That Frustrate
Scenario Why It Frustrates
Password rules that are excessively complex Users cannot create a memorable password
Dropdown with 200+ country options Slower than typing; users scroll endlessly
Forced sequence when steps are independent Users cannot fill in information in their preferred order
Preventing paste into a "confirm email" field Users must retype, increasing error rate
Requiring phone number when it is not needed Users feel the product is collecting unnecessary data
The Constraint Spectrum
Too few constraints          Just right               Too many constraints
      |                         |                           |
  Error-prone             Error-free, smooth          Frustrating, slow
  Confusing               Guided                      Patronizing
  Flexible                Efficient                   Rigid

The goal is the middle zone: enough constraints to prevent errors, not so many that users feel restricted.


Anti-Patterns: Over-Constraining Users

Anti-Pattern Problem Better Approach
Preventing copy-paste in forms Increases errors by forcing manual re-entry Allow paste; validate the result
Session timeouts without warning Users lose work without notice Warn before timeout, offer extension
Forced password change every 90 days Users choose weaker passwords to cope Monitor for breaches instead
Maximum line length in text fields Users cannot write naturally Use soft limits with warnings, not hard limits
Blocking form submission for non-critical warnings Users cannot proceed despite having correct intent Distinguish errors (block) from warnings (allow with note)
Requiring all fields when most are optional Users abandon the form Mark truly required fields; make the rest optional

Constraint Audit Checklist

Error Prevention
  • All form inputs have appropriate type constraints (number fields accept only numbers, etc.).
  • Date and time inputs use pickers rather than free-text fields.
  • Required fields are clearly marked and enforced before submission.
  • Actions that depend on preconditions are disabled (with explanation) until preconditions are met.
  • Destructive actions require confirmation or offer undo.
Input Quality
  • Input masks or autocomplete are used for structured data (phone, postal code, credit card).
  • Range constraints are enforced with clear min/max indicators.
  • Real-time validation provides feedback as the user types.
  • Error messages explain what is expected, not just what is wrong.
Sequence and Flow
  • Multi-step processes enforce logical order when necessary.
  • Independent steps can be completed in any order.
  • The current step and remaining steps are visible.
  • Users can go back to previous steps without losing data.
Recovery
  • Undo is available for all non-destructive actions.
  • Soft delete (trash/archive) is used instead of permanent deletion.
  • Autosave prevents data loss.
  • Session recovery restores unsaved work after timeout or crash.
Appropriateness
  • No constraint exists purely for the system's convenience at the user's expense.
  • Constraints match the severity of the potential error.
  • Users are not forced to provide information that is not necessary for the task.
  • Paste is allowed in all text fields.
  • Flexible input formats are accepted and normalized (phone numbers, dates).
1# Constraints: Limiting Actions to Prevent Errors
2 
3Constraints are design elements that limit the possible actions a user can take. Used well, they make errors impossible or improbable. The underlying principle is simple: instead of telling users what not to do, make the wrong action physically, logically, or semantically impossible. Every constraint added is one fewer error the user can make.
4 
5## Four Constraint Types
6 
7### Physical Constraints
8 
9Physical constraints use shape, size, or material properties to restrict actions.
10 
11| Constraint | How It Works | Example |
12|-----------|-------------|---------|
13| Shape exclusion | Parts only fit one way | USB-A plug has a correct orientation; USB-C fits both ways |
14| Size limitation | Object is too large/small for wrong use | A large plug cannot fit a small socket |
15| Material resistance | Force required prevents accidental activation | Childproof medicine bottle requires push-and-twist |
16| Barrier | Physical blockage prevents access | Guardrails prevent cars from leaving the road |
17 
18**Digital equivalent**: Input masks, character limits, file type restrictions, and minimum/maximum values.
19 
20### Cultural Constraints
21 
22Cultural constraints rely on shared social conventions and learned norms to guide behavior.
23 
24| Constraint | How It Works | Example |
25|-----------|-------------|---------|
26| Social norms | Expected behavior in context | Whispering in a library, facing forward in an elevator |
27| Color conventions | Shared color meanings | Red for stop/danger, green for go/safe |
28| Positional conventions | Expected placement of elements | OK/Cancel button order (platform-dependent) |
29| Interaction conventions | Learned digital behaviors | Double-click to open, single-click to select |
30 
31**Design implication**: Cultural constraints are powerful but invisible. Violating them causes confusion even when the system technically works.
32 
33### Semantic Constraints
34 
35Semantic constraints use the meaning of a situation to limit the set of possible actions.
36 
37| Constraint | How It Works | Example |
38|-----------|-------------|---------|
39| Contextual meaning | Meaning restricts logical placement | A rearview mirror only makes sense facing the rear |
40| Role meaning | Knowledge of purpose limits actions | A windshield is obviously not a door |
41| Temporal meaning | Timing restricts when actions make sense | Cannot review an order before adding items |
42 
43**Digital equivalent**: Contextual menus that show only relevant actions, conditional fields that appear based on prior selections.
44 
45### Logical Constraints
46 
47Logical constraints use reasoning to limit what is possible through exclusion.
48 
49| Constraint | How It Works | Example |
50|-----------|-------------|---------|
51| Process of elimination | Only one option remains | Last puzzle piece can only go in the remaining hole |
52| Mutual exclusion | Choosing A makes B impossible | Radio buttons: selecting one deselects others |
53| Dependency chains | Step B requires step A | Cannot format text before selecting it |
54| Completeness check | All parts must be present | Form cannot submit until all required fields are filled |
55 
56---
57 
58## Digital Constraint Implementations
59 
60### Input Validation as Constraint
61 
62| Validation Type | What It Constrains | Implementation |
63|----------------|-------------------|----------------|
64| **Type restriction** | Only numbers, only letters, specific format | `input type="email"`, `type="tel"`, regex patterns |
65| **Range restriction** | Minimum and maximum values | `min="0" max="100"`, date ranges, slider bounds |
66| **Length restriction** | Character count | `maxlength="280"`, with visible counter |
67| **Format restriction** | Specific pattern required | Input mask for phone: (___) ___-____ |
68| **Enum restriction** | Only predefined options allowed | Dropdown, radio buttons, autocomplete with fixed list |
69| **Real-time validation** | Invalid input rejected as typed | Inline error showing before form submission |
70 
71### Best Practices for Input Validation
72 
73- Prefer prevention over detection: use a date picker instead of validating a typed date.
74- Validate in real time, not only on submit. Show inline feedback as the user types.
75- When rejecting input, explain what is expected: "Phone number must be 10 digits" not "Invalid input."
76- Accept flexible formats and normalize internally: "1234567890", "(123) 456-7890", and "123-456-7890" should all be accepted for a phone number.
77 
78### Progressive Disclosure as Constraint
79 
80Progressive disclosure constrains what users see and interact with, reducing cognitive load and preventing premature actions.
81 
82| Pattern | What It Constrains | Example |
83|---------|-------------------|---------|
84| **Collapsed sections** | Hides advanced options until requested | "Advanced settings" expandable panel |
85| **Wizard / stepper** | Shows only current step | Multi-step checkout flow |
86| **Conditional fields** | Shows fields only when relevant | "Other" text field appears only when "Other" is selected |
87| **Role-based visibility** | Shows features based on permissions | Admin panel visible only to admin users |
88| **Contextual menus** | Shows only actions relevant to the selected item | Right-click menu changes based on element type |
89 
90### Disabled States and Forced Sequences
91 
92Disabled states constrain users by making actions visually present but temporarily unavailable.
93 
94| Pattern | When to Use | How to Implement |
95|---------|------------|-----------------|
96| **Disabled button** | Required precondition not met | Gray out button, add tooltip explaining why |
97| **Locked wizard step** | Prior steps incomplete | Show step indicator but prevent skipping ahead |
98| **Conditional enable** | Depends on another field's value | Enable "Confirm" only after checkbox is checked |
99| **Time-gated action** | Action requires waiting period | "You can send again in 30 seconds" with countdown |
100| **Auth-gated action** | Requires login or elevated permissions | Show the action but redirect to login on click |
101 
102**Critical rule for disabled states**: Always explain why the action is disabled. A disabled button with no explanation is a constraint that creates frustration rather than guiding users.
103 
104| Implementation | User Experience |
105|---------------|----------------|
106| Disabled button, no explanation | "Why can't I click this? Is it broken?" |
107| Disabled button with tooltip | "I see -- I need to fill in the required fields first." |
108| Disabled button with inline helper text | "Fill in all required fields to enable submission." |
109 
110### Undo/Redo as Error Recovery Constraint
111 
112Undo/redo does not prevent errors, but it constrains the impact of errors by making them reversible.
113 
114| Pattern | Implementation | Example |
115|---------|---------------|---------|
116| **Immediate undo** | Toast notification with "Undo" link | Gmail "Message sent. Undo" |
117| **Action history** | List of recent actions with rollback | Google Docs version history |
118| **Soft delete** | Items move to trash, not permanently deleted | Recycle bin, 30-day retention |
119| **Autosave with versions** | Every change is saved and reversible | Google Docs, Figma auto-save |
120| **Confirmation dialog** | "Are you sure?" before destructive action | Delete account confirmation |
121 
122### When to Use Confirmation Dialogs
123 
124Confirmation dialogs are appropriate only for:
125- **Irreversible** actions (delete account, send broadcast email)
126- **High-consequence** actions (charge credit card, publish to production)
127- **Unusual** actions (something the user does rarely and might have triggered accidentally)
128 
129They are NOT appropriate for:
130- Routine actions (saving a document, closing a tab)
131- Actions that are easily reversible (moving an item, changing a setting)
132- Frequent operations (every dialog slows the user down and trains them to click "OK" without reading)
133 
134---
135 
136## Constraint Design Patterns by Use Case
137 
138### E-Commerce Checkout
139 
140| Constraint | Type | Purpose |
141|-----------|------|---------|
142| Cannot proceed to payment without shipping address | Logical (forced sequence) | Prevents incomplete orders |
143| Credit card field accepts only digits with auto-formatting | Physical (input mask) | Prevents format errors |
144| "Place Order" disabled until terms checkbox is checked | Logical (dependency) | Ensures legal compliance |
145| Quantity selector with min=1, max=99 | Physical (range) | Prevents zero or absurd quantities |
146| Address autocomplete from verified database | Semantic (constrained options) | Prevents undeliverable addresses |
147 
148### User Registration
149 
150| Constraint | Type | Purpose |
151|-----------|------|---------|
152| Password strength meter with minimum requirements | Physical (validation) | Prevents weak passwords |
153| Email format validation | Physical (format) | Prevents invalid email addresses |
154| Username uniqueness check (real-time) | Logical (exclusion) | Prevents duplicate accounts |
155| Age gate with date picker | Semantic (contextual) | Prevents underage registration |
156| CAPTCHA before submission | Cultural (convention) + Logical | Prevents automated abuse |
157 
158### Content Management
159 
160| Constraint | Type | Purpose |
161|-----------|------|---------|
162| Draft / Published / Archived states with transitions | Logical (forced sequence) | Content must be reviewed before publishing |
163| Character limits on titles and descriptions | Physical (length) | Prevents layout-breaking content |
164| Image upload restricted to specific formats and sizes | Physical (type + size) | Prevents unsupported media |
165| Scheduled publish date must be in the future | Semantic (temporal) | Prevents backdated publishing |
166| Role-based editing permissions | Cultural (authority) + Logical | Prevents unauthorized changes |
167 
168---
169 
170## When Constraints Help vs. Frustrate
171 
172### Constraints That Help
173 
174| Scenario | Why It Helps |
175|----------|-------------|
176| Date picker instead of free text | Users cannot enter an invalid date format |
177| Disabled "Next" until required fields are complete | Users cannot skip required information |
178| Autocomplete for city/state from zip code | Reduces typing and prevents mismatched data |
179| File upload limit with clear message | Prevents timeout errors on oversized files |
180| Character counter approaching limit | Users adjust their content proactively |
181 
182### Constraints That Frustrate
183 
184| Scenario | Why It Frustrates |
185|----------|------------------|
186| Password rules that are excessively complex | Users cannot create a memorable password |
187| Dropdown with 200+ country options | Slower than typing; users scroll endlessly |
188| Forced sequence when steps are independent | Users cannot fill in information in their preferred order |
189| Preventing paste into a "confirm email" field | Users must retype, increasing error rate |
190| Requiring phone number when it is not needed | Users feel the product is collecting unnecessary data |
191 
192### The Constraint Spectrum
193 
194```
195Too few constraints Just right Too many constraints
196 | | |
197 Error-prone Error-free, smooth Frustrating, slow
198 Confusing Guided Patronizing
199 Flexible Efficient Rigid
200```
201 
202The goal is the middle zone: enough constraints to prevent errors, not so many that users feel restricted.
203 
204---
205 
206## Anti-Patterns: Over-Constraining Users
207 
208| Anti-Pattern | Problem | Better Approach |
209|-------------|---------|----------------|
210| **Preventing copy-paste in forms** | Increases errors by forcing manual re-entry | Allow paste; validate the result |
211| **Session timeouts without warning** | Users lose work without notice | Warn before timeout, offer extension |
212| **Forced password change every 90 days** | Users choose weaker passwords to cope | Monitor for breaches instead |
213| **Maximum line length in text fields** | Users cannot write naturally | Use soft limits with warnings, not hard limits |
214| **Blocking form submission for non-critical warnings** | Users cannot proceed despite having correct intent | Distinguish errors (block) from warnings (allow with note) |
215| **Requiring all fields when most are optional** | Users abandon the form | Mark truly required fields; make the rest optional |
216 
217---
218 
219## Constraint Audit Checklist
220 
221### Error Prevention
222 
223- [ ] All form inputs have appropriate type constraints (number fields accept only numbers, etc.).
224- [ ] Date and time inputs use pickers rather than free-text fields.
225- [ ] Required fields are clearly marked and enforced before submission.
226- [ ] Actions that depend on preconditions are disabled (with explanation) until preconditions are met.
227- [ ] Destructive actions require confirmation or offer undo.
228 
229### Input Quality
230 
231- [ ] Input masks or autocomplete are used for structured data (phone, postal code, credit card).
232- [ ] Range constraints are enforced with clear min/max indicators.
233- [ ] Real-time validation provides feedback as the user types.
234- [ ] Error messages explain what is expected, not just what is wrong.
235 
236### Sequence and Flow
237 
238- [ ] Multi-step processes enforce logical order when necessary.
239- [ ] Independent steps can be completed in any order.
240- [ ] The current step and remaining steps are visible.
241- [ ] Users can go back to previous steps without losing data.
242 
243### Recovery
244 
245- [ ] Undo is available for all non-destructive actions.
246- [ ] Soft delete (trash/archive) is used instead of permanent deletion.
247- [ ] Autosave prevents data loss.
248- [ ] Session recovery restores unsaved work after timeout or crash.
249 
250### Appropriateness
251 
252- [ ] No constraint exists purely for the system's convenience at the user's expense.
253- [ ] Constraints match the severity of the potential error.
254- [ ] Users are not forced to provide information that is not necessary for the task.
255- [ ] Paste is allowed in all text fields.
256- [ ] Flexible input formats are accepted and normalized (phone numbers, dates).
257 

Discussion