@addai/flows-mcp 1.1.0-rc.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,285 +1,285 @@
1
- # Anti-patterns
2
-
3
- Specific mistakes Claude (and humans) make repeatedly. Each has a fix.
4
-
5
- ## AP1 — Vertical-stacked flows
6
-
7
- **Mistake:** Passing `position` values to `add_nodes` at all. Even "smart" guesses like incrementing `y` produce a vertical column. Whether you stack `y` deliberately or just copy positions from somewhere, the result is a flow that reads top-to-bottom like a debug log.
8
-
9
- **Why it's wrong:**
10
- - Unreadable on a wide canvas (most of the canvas is empty space).
11
- - Violates team convention (P9: horizontal is default).
12
- - `validate_flow` will issue `LAYOUT_VERTICAL_DRIFT` warnings.
13
- - Users will tell you "you built it vertically" and you'll have to redo it.
14
-
15
- **Do instead:**
16
- - Pass NO `position` to `add_nodes`. EVER. It auto-places horizontally (right of the rightmost existing node, same row).
17
- - For branches (if/switch/loop), still pass no position — pass `sourceHandle` and let the server lay it out, or call `autolayout({flow_id})` once at the end.
18
- - If positions got messy during a refactor, call `autolayout({flow_id})` to fix the entire flow.
19
-
20
- ## AP1b — Trailing `goal` node after a terminal page
21
-
22
- **Mistake:** Building `[page (form)] → [process] → [page (thanks)] → [goal]`. The final `goal` node is redundant — the thank-you page IS the terminator.
23
-
24
- **Why it's wrong:**
25
- - Unnecessary node clutters the canvas.
26
- - The flow now has a "phantom" step after the user already saw the confirmation page — execution wraps but adds no value.
27
- - The user (and Claude) gets confused about which node is the actual terminator.
28
-
29
- **Do instead:**
30
- - Set `data.isGoal: true` and `data.goalName: "..."` on the final `page` node. That page becomes the goal directly.
31
- - Same applies to `isExit: true` for alternative terminations.
32
- - A separate `goal` node is only needed when the terminator is NOT a page (e.g., after a `respondToWebhook` that returns JSON to an API caller, the `goal` is the next-and-final node).
33
-
34
- ## AP2 — `{{}}` inside a code node
35
-
36
- **Mistake:**
37
- ```javascript
38
- const email = "{{trigger.body.email}}"; // ← does NOT resolve
39
- ```
40
-
41
- **Why it's wrong:** `{{}}` syntax is only resolved in node *config fields*. Code nodes run in a JavaScript sandbox where `{{}}` is a literal string.
42
-
43
- **Do instead:**
44
- ```javascript
45
- const email = $("trigger").body.email;
46
- ```
47
-
48
- ## AP3 — `$()` inside custom node code
49
-
50
- **Mistake:** Using `$("nodeId")` inside a custom node's `code`.
51
-
52
- **Why it's wrong:** Custom nodes run in a separate sandbox. They don't have access to other nodes' outputs — only the declared `inputs` and `secrets`.
53
-
54
- **Do instead:**
55
- ```javascript
56
- const url = inputs.endpoint; // declared in input_schema
57
- const token = secrets.API_TOKEN; // declared in secret_requirements
58
- ```
59
-
60
- ## AP4 — Forgetting `customVersionId`
61
-
62
- **Mistake:** Inserting a `customNode` with only `customNodeId`, expecting it to use "the latest version."
63
-
64
- **Why it's wrong:** Custom node versions do not auto-update on publish (deliberate design decision). A flow without `customVersionId` will fail at runtime — there is no implicit latest.
65
-
66
- **Do instead:** Always pin:
67
- ```
68
- {type: "customNode", data: {customNodeId: "cn_x", customVersionId: "v_abc"}}
69
- ```
70
-
71
- To upgrade later, edit `customVersionId` deliberately and validate.
72
-
73
- ## AP5 — Wrong `sourceHandle` on branching nodes
74
-
75
- **Mistake:** Adding an edge from an `if` node without `sourceHandle`, or using `"yes"`/`"no"` instead of `"true"`/`"false"`.
76
-
77
- **Why it's wrong:** Branching nodes require specific handle values. Wrong handle → edge ignored at runtime → mysterious "the flow just stopped."
78
-
79
- **Do instead:** Look up handles per node type:
80
-
81
- | Node type | Valid handles |
82
- |---|---|
83
- | `if` | `"true"`, `"false"` |
84
- | `switch` | case `outputLabel`s, or `"default"` |
85
- | `loop` | `"loop"`, `"done"`, `"fail"` |
86
- | `review` | `"option_0"`, `"option_1"`, … |
87
-
88
- Or just call `describe_node_type(type)` and read `source_handles`.
89
-
90
- ## AP6 — `set_variable` inside a `loop`
91
-
92
- **Mistake:** Calling `set_variable` from within a loop iteration to accumulate state.
93
-
94
- **Why it's wrong:** Variables are flow-scoped and shared across concurrent iterations. Race condition; values overwrite each other unpredictably.
95
-
96
- **Do instead:** Use the `code` node's return value to push items onto an array stored as variable, OR use a state store (`set_state`, Phase 3). For now: collect via code node after the `loop` `done` handle.
97
-
98
- ## AP7 — Recursion via `claudeCode`
99
-
100
- **Mistake:** A flow's `claudeCode` node dispatches work to a paired Claude Code agent. That agent happens to be using *this* MCP — and starts building a flow that itself has a `claudeCode` node.
101
-
102
- **Why it's wrong:** Infinite recursion. Resource exhaustion. Possible runaway billing.
103
-
104
- **Do instead:** When using `claudeCode`, restrict its prompt to tasks that do **not** modify flows. Better: scope the paired Claude Code agent's MCPs to exclude `addai-flows`.
105
-
106
- ## AP8 — Publishing without `pre_publish_check`
107
-
108
- **Mistake:** Calling `publish_flow` directly because validation passed.
109
-
110
- **Why it's wrong:** Validation is necessary but not sufficient. The flow may have inline secrets, deprecated nodes, failing snapshot tests, or unbacked Vault references. All of those will pass `validate_flow` but should still block publish.
111
-
112
- **Do instead:**
113
- ```
114
- pre_publish_check(flow_id) # → ready or blocked with reasons
115
- publish_flow(flow_id) # only if check returned ready
116
- ```
117
-
118
- (`pre_publish_check` is Phase 2 — until then, run validate_flow + manual inspection for inline secrets in code nodes.)
119
-
120
- ## AP9 — Polling instead of streaming
121
-
122
- **Mistake:** Wrapping `test_flow` in a manual loop because you want to watch progress.
123
-
124
- **Why it's wrong:** `test_flow` already polls internally. Wrapping it again multiplies the poll rate and wastes tokens.
125
-
126
- **Do instead:** Use `test_flow_stream` (Phase 2 — SSE-based progress events). For Phase 1, `test_flow` is fine; don't add an outer loop.
127
-
128
- ## AP10 — Saving fixtures with PII
129
-
130
- **Mistake:** `save_fixture(name, payload)` where the payload contains real user emails / phone numbers / card numbers.
131
-
132
- **Why it's wrong:** Fixtures get reused in tests, shared in logs, possibly exported. Real PII in test data is a compliance leak.
133
-
134
- **Do instead:**
135
- - The MCP applies `data_masking_default=true` to fixtures by default — but only on display, not on save.
136
- - Run the payload through `detect_pii(flow_id)` (Phase 2) before saving, or manually sanitize.
137
- - Replace real values with synthetic ones (`user@example.com`, `+1 555 000 0000`).
138
-
139
- ## AP11 — Vertical drift from "I'll just add one more node"
140
-
141
- **Mistake:** Repeatedly adding nodes downstream without thinking about the canvas. Result: a flow that has technically horizontal positions but is *narrower than tall* because branches stacked deeply.
142
-
143
- **Why it's wrong:** `validate_flow` raises `LAYOUT_VERTICAL_DRIFT` when `height > 1.2 × width` with < 3 active branches. Looks weird; harder for the human to read.
144
-
145
- **Do instead:** After significant additions, run `autolayout(flow_id)`. It's idempotent — safe to call any time.
146
-
147
- ## AP12 — Hand-rolling validation
148
-
149
- **Mistake:** Writing your own checks ("does this flow have a trigger?") inside Claude's response instead of calling `validate_flow`.
150
-
151
- **Why it's wrong:** Your hand-rolled check will drift from the real validator. It will miss rules that the server checks (template syntax, custom-node version pinning, schema version compatibility). Worse, it gives a false sense of correctness.
152
-
153
- **Do instead:** Always `validate_flow`. The server is authoritative.
154
-
155
- ## AP14 — Unlabeled forms
156
-
157
- **Mistake:** Adding `page` element children with empty `label` / `placeholder` / `content`. The form renders as a stack of identical grey rectangles with nothing telling the user what to fill in.
158
-
159
- **Why it's wrong:**
160
- - Users see three empty boxes and don't know what's being asked.
161
- - Submission data is keyed by `label` (`{{form.submissionData["Your name"]}}`), so empty labels mean empty keys — downstream templates can't reference anything.
162
- - It looks unprofessional and the user will complain ("the form is terrible").
163
-
164
- **Do instead — every form MUST have:**
165
-
166
- 1. A `textBlock` element FIRST (use `variant: "h2"` or `"h1"`) explaining what the form is for.
167
- 2. Every input element with a **non-empty `label`** — short, action-oriented, unique within the form.
168
- 3. Every input with a **`placeholder`** showing what valid input looks like (`"jane@example.com"`, not `"Enter email"`).
169
- 4. **`required: true`** on fields that are actually required, with the rest left optional.
170
- 5. **`width: "half"`** on pairs of short related fields (first/last name, email/phone) so they sit on one row.
171
- 6. The submit button with a **meaningful `label`** (`"Send feedback"`, `"Get my quote"`) — not the default `"Continue"`.
172
- 7. The right element TYPE per field — `email` for emails, `dropdown` for finite-option lists, `longText` only for genuinely multi-line input.
173
-
174
- **Quick check before saving the page node:** ask yourself "if a stranger opened this form, would they know what to fill in without me explaining?" If no, the labels/headings are missing.
175
-
176
- See Recipe 1 in `recipes.md` for a fully-fleshed example.
177
-
178
- ## AP15 — Form without a submit button
179
-
180
- **Mistake:** Building a `page` node with input elements but no `button` element. Users fill the form and have nowhere to click — the flow is stuck forever.
181
-
182
- **Why it's wrong:** A page node advances to its `right` source handle only when the user presses a submit-action button. Without one, the page never completes. There is no implicit Continue button — *you must add one*. `validate_flow` raises `PAGE_MISSING_SUBMIT_BUTTON` for non-terminal pages without a `buttonAction: "submit"` button.
183
-
184
- **Do instead:** Every non-terminal page MUST include at least one button element. The shape:
185
-
186
- ```js
187
- {
188
- id: "submit",
189
- type: "button",
190
- buttonText: "Send feedback", // NOT `label` — the field is buttonText
191
- buttonAction: "submit", // submit | link | stop | restart
192
- buttonAlign: "left",
193
- buttonColor: "#3b82f6",
194
- }
195
- ```
196
-
197
- **Button action values (from `describe_page_element("button")`):**
198
- - `submit` (default) — fires the page's `right` source handle and advances the flow. The typical Continue/Send button.
199
- - `link` — opens `buttonLink` in same tab or new tab (`buttonLinkNewTab`). Does NOT advance the flow.
200
- - `stop` — terminates the flow without advancing.
201
- - `restart` — restarts the flow from the trigger.
202
-
203
- **Terminal pages exemption:** pages with `isGoal: true` or `isExit: true` don't need a submit button (the flow has already terminated), though you may still want a `link` button ("Back to home") or a `restart` button ("Submit another").
204
-
205
- ## AP16 — Button using `label` instead of `buttonText`
206
-
207
- **Mistake:** `{type: "button", label: "Continue", action: "submit"}`.
208
-
209
- **Why it's wrong:** The page renderer reads `buttonText` / `buttonAction` / `buttonAlign` / `buttonColor` / `buttonLink` / `buttonLinkNewTab`. The generic `label` / `action` keys from other element types do nothing on a button — your button shows the literal default text ("Continue") and uses the default action.
210
-
211
- **Do instead:** Call `describe_page_element("button")` before adding a button element. Use the exact field names: `buttonText`, `buttonAction`, `buttonAlign`, `buttonColor`, `buttonLink`, `buttonLinkNewTab`, `width`.
212
-
213
- ## AP17 — Wrong condition-logic key on `if` / `switch`
214
-
215
- **Mistake:** Writing `data.conditionLogic: "and"` on an `if` node (or `"or"`).
216
-
217
- **Why it's wrong:** The canvas and runtime read `logicOperator` (UPPERCASE `"AND"` or `"OR"`). `conditionLogic` was an early-release key that never landed in production. Lowercase values are also ignored — the toggle silently defaults to AND.
218
-
219
- **Do instead:**
220
- ```js
221
- {type: "if", data: {
222
- conditions: [...],
223
- logicOperator: "OR", // UPPERCASE; "AND" or "OR" only
224
- }}
225
- ```
226
-
227
- Same on `switch` cases: each case's `logicOperator` is uppercase.
228
-
229
- ## AP18 — `aiSwitch` route using `contextDescription`
230
-
231
- **Mistake:** Routes shaped as `{id, label, outputLabel, contextDescription: "..."}`.
232
-
233
- **Why it's wrong:** The canvas Context textarea reads from `route.context`, NOT `route.contextDescription`. Writing the wrong key produces blank textareas in the editor — the routing prompt sees no context per route, so the LLM has nothing to discriminate on.
234
-
235
- **Do instead:**
236
- ```js
237
- {type: "aiSwitch", data: {
238
- routes: [
239
- {id: "r1", label: "Refund", outputLabel: "Refund",
240
- context: "User wants a refund — wording mentions money back, return, refund"},
241
- ...
242
- ]
243
- }}
244
- ```
245
-
246
- Same when changing the credential, the canvas auto-derives `provider` and resets `model`. If you set `credentialId` programmatically, also set `provider` to the matching enum and pick a `model` valid for that provider.
247
-
248
- ## AP19 — Terminal page using `goalName` only
249
-
250
- **Mistake:** `{type: "page", data: {isGoal: true, goalName: "Signed up"}}`.
251
-
252
- **Why it's wrong:** The canvas Goal picker reads `goalId` (FK to `end_conditions.goals[]`). When you write only `goalName`, the picker shows "Goal: (none selected)" — even though stats record the goal correctly, the editor UX is broken.
253
-
254
- **Do instead:** Either:
255
- - Reference an existing goal: set `goalId` AND `goalName` (matching the saved goal row).
256
- - Or use a `goal` / `exit` node instead of the form-as-goal pattern.
257
-
258
- Same with `isExit: true` — set both `exitId` and `exitName`.
259
-
260
- ## AP20 — `httpRequest.authentication` missing `credential` type
261
-
262
- **Mistake:** Reading the catalog and only seeing `none / bearer / basic / apikey` as auth types.
263
-
264
- **Why it's wrong:** The production canvas defaults to `{type: "credential", credentialId: "<vault id>"}`. This references a saved Vault credential — the most common pattern. Don't write inline tokens if a Vault credential exists for the upstream API.
265
-
266
- **Do instead:** `describe_node_type("httpRequest")` shows the full set. Prefer `type: "credential"` when the user has a Vault item set up for the API.
267
-
268
- ## AP21 — Missing `claudeCode.retryConfig` / `offlineBehavior` / `fallbackSteps`
269
-
270
- **Mistake:** Building a `claudeCode` node and assuming `onError: "stop"` is sufficient. The user later finds runs failing because their preferred Claude Code agent was offline.
271
-
272
- **Why it's wrong:** `claudeCode` has three production-grade resiliency knobs that the catalog spells out: `offlineBehavior` ("error" or "queue" when agent offline), `retryConfig: {maxRetries, retryDelaySeconds}`, and `fallbackSteps[]` (an ordered list of backup agents with their own retries). If you don't configure them, you get the strict default (error immediately, no retry).
273
-
274
- **Do instead:** For production workflows, set these explicitly. Example: queue if offline, retry twice, then fall back to a different agent:
275
- ```js
276
- {
277
- type: "claudeCode",
278
- data: {
279
- agentId: "agent_primary",
280
- offlineBehavior: "queue",
281
- retryConfig: {maxRetries: 2, retryDelaySeconds: 30},
282
- fallbackSteps: [{agentId: "agent_backup", waitSeconds: 60, retries: [{maxRetries: 1, retryDelaySeconds: 10}]}],
283
- }
284
- }
285
- ```
1
+ # Anti-patterns
2
+
3
+ Specific mistakes Claude (and humans) make repeatedly. Each has a fix.
4
+
5
+ ## AP1 — Vertical-stacked flows
6
+
7
+ **Mistake:** Passing `position` values to `add_nodes` at all. Even "smart" guesses like incrementing `y` produce a vertical column. Whether you stack `y` deliberately or just copy positions from somewhere, the result is a flow that reads top-to-bottom like a debug log.
8
+
9
+ **Why it's wrong:**
10
+ - Unreadable on a wide canvas (most of the canvas is empty space).
11
+ - Violates team convention (P9: horizontal is default).
12
+ - `validate_flow` will issue `LAYOUT_VERTICAL_DRIFT` warnings.
13
+ - Users will tell you "you built it vertically" and you'll have to redo it.
14
+
15
+ **Do instead:**
16
+ - Pass NO `position` to `add_nodes`. EVER. It auto-places horizontally (right of the rightmost existing node, same row).
17
+ - For branches (if/switch/loop), still pass no position — pass `sourceHandle` and let the server lay it out, or call `autolayout({flow_id})` once at the end.
18
+ - If positions got messy during a refactor, call `autolayout({flow_id})` to fix the entire flow.
19
+
20
+ ## AP1b — Trailing `goal` node after a terminal page
21
+
22
+ **Mistake:** Building `[page (form)] → [process] → [page (thanks)] → [goal]`. The final `goal` node is redundant — the thank-you page IS the terminator.
23
+
24
+ **Why it's wrong:**
25
+ - Unnecessary node clutters the canvas.
26
+ - The flow now has a "phantom" step after the user already saw the confirmation page — execution wraps but adds no value.
27
+ - The user (and Claude) gets confused about which node is the actual terminator.
28
+
29
+ **Do instead:**
30
+ - Set `data.isGoal: true` and `data.goalName: "..."` on the final `page` node. That page becomes the goal directly.
31
+ - Same applies to `isExit: true` for alternative terminations.
32
+ - A separate `goal` node is only needed when the terminator is NOT a page (e.g., after a `respondToWebhook` that returns JSON to an API caller, the `goal` is the next-and-final node).
33
+
34
+ ## AP2 — `{{}}` inside a code node
35
+
36
+ **Mistake:**
37
+ ```javascript
38
+ const email = "{{trigger.body.email}}"; // ← does NOT resolve
39
+ ```
40
+
41
+ **Why it's wrong:** `{{}}` syntax is only resolved in node *config fields*. Code nodes run in a JavaScript sandbox where `{{}}` is a literal string.
42
+
43
+ **Do instead:**
44
+ ```javascript
45
+ const email = $("trigger").body.email;
46
+ ```
47
+
48
+ ## AP3 — `$()` inside custom node code
49
+
50
+ **Mistake:** Using `$("nodeId")` inside a custom node's `code`.
51
+
52
+ **Why it's wrong:** Custom nodes run in a separate sandbox. They don't have access to other nodes' outputs — only the declared `inputs` and `secrets`.
53
+
54
+ **Do instead:**
55
+ ```javascript
56
+ const url = inputs.endpoint; // declared in input_schema
57
+ const token = secrets.API_TOKEN; // declared in secret_requirements
58
+ ```
59
+
60
+ ## AP4 — Forgetting `customVersionId`
61
+
62
+ **Mistake:** Inserting a `customNode` with only `customNodeId`, expecting it to use "the latest version."
63
+
64
+ **Why it's wrong:** Custom node versions do not auto-update on publish (deliberate design decision). A flow without `customVersionId` will fail at runtime — there is no implicit latest.
65
+
66
+ **Do instead:** Always pin:
67
+ ```
68
+ {type: "customNode", data: {customNodeId: "cn_x", customVersionId: "v_abc"}}
69
+ ```
70
+
71
+ To upgrade later, edit `customVersionId` deliberately and validate.
72
+
73
+ ## AP5 — Wrong `sourceHandle` on branching nodes
74
+
75
+ **Mistake:** Adding an edge from an `if` node without `sourceHandle`, or using `"yes"`/`"no"` instead of `"true"`/`"false"`.
76
+
77
+ **Why it's wrong:** Branching nodes require specific handle values. Wrong handle → edge ignored at runtime → mysterious "the flow just stopped."
78
+
79
+ **Do instead:** Look up handles per node type:
80
+
81
+ | Node type | Valid handles |
82
+ |---|---|
83
+ | `if` | `"true"`, `"false"` |
84
+ | `switch` | case `outputLabel`s, or `"default"` |
85
+ | `loop` | `"loop"`, `"done"`, `"fail"` |
86
+ | `review` | `"option_0"`, `"option_1"`, … |
87
+
88
+ Or just call `describe_node_type(type)` and read `source_handles`.
89
+
90
+ ## AP6 — `set_variable` inside a `loop`
91
+
92
+ **Mistake:** Calling `set_variable` from within a loop iteration to accumulate state.
93
+
94
+ **Why it's wrong:** Variables are flow-scoped and shared across concurrent iterations. Race condition; values overwrite each other unpredictably.
95
+
96
+ **Do instead:** Use the `code` node's return value to push items onto an array stored as variable, OR use a state store (`set_state`, Phase 3). For now: collect via code node after the `loop` `done` handle.
97
+
98
+ ## AP7 — Recursion via `claudeCode`
99
+
100
+ **Mistake:** A flow's `claudeCode` node dispatches work to a paired Claude Code agent. That agent happens to be using *this* MCP — and starts building a flow that itself has a `claudeCode` node.
101
+
102
+ **Why it's wrong:** Infinite recursion. Resource exhaustion. Possible runaway billing.
103
+
104
+ **Do instead:** When using `claudeCode`, restrict its prompt to tasks that do **not** modify flows. Better: scope the paired Claude Code agent's MCPs to exclude `addai-flows`.
105
+
106
+ ## AP8 — Publishing without `pre_publish_check`
107
+
108
+ **Mistake:** Calling `publish_flow` directly because validation passed.
109
+
110
+ **Why it's wrong:** Validation is necessary but not sufficient. The flow may have inline secrets, deprecated nodes, failing snapshot tests, or unbacked Vault references. All of those will pass `validate_flow` but should still block publish.
111
+
112
+ **Do instead:**
113
+ ```
114
+ pre_publish_check(flow_id) # → ready or blocked with reasons
115
+ publish_flow(flow_id) # only if check returned ready
116
+ ```
117
+
118
+ (`pre_publish_check` is Phase 2 — until then, run validate_flow + manual inspection for inline secrets in code nodes.)
119
+
120
+ ## AP9 — Polling instead of streaming
121
+
122
+ **Mistake:** Wrapping `test_flow` in a manual loop because you want to watch progress.
123
+
124
+ **Why it's wrong:** `test_flow` already polls internally. Wrapping it again multiplies the poll rate and wastes tokens.
125
+
126
+ **Do instead:** Use `test_flow_stream` (Phase 2 — SSE-based progress events). For Phase 1, `test_flow` is fine; don't add an outer loop.
127
+
128
+ ## AP10 — Saving fixtures with PII
129
+
130
+ **Mistake:** `save_fixture(name, payload)` where the payload contains real user emails / phone numbers / card numbers.
131
+
132
+ **Why it's wrong:** Fixtures get reused in tests, shared in logs, possibly exported. Real PII in test data is a compliance leak.
133
+
134
+ **Do instead:**
135
+ - The MCP applies `data_masking_default=true` to fixtures by default — but only on display, not on save.
136
+ - Run the payload through `detect_pii(flow_id)` (Phase 2) before saving, or manually sanitize.
137
+ - Replace real values with synthetic ones (`user@example.com`, `+1 555 000 0000`).
138
+
139
+ ## AP11 — Vertical drift from "I'll just add one more node"
140
+
141
+ **Mistake:** Repeatedly adding nodes downstream without thinking about the canvas. Result: a flow that has technically horizontal positions but is *narrower than tall* because branches stacked deeply.
142
+
143
+ **Why it's wrong:** `validate_flow` raises `LAYOUT_VERTICAL_DRIFT` when `height > 1.2 × width` with < 3 active branches. Looks weird; harder for the human to read.
144
+
145
+ **Do instead:** After significant additions, run `autolayout(flow_id)`. It's idempotent — safe to call any time.
146
+
147
+ ## AP12 — Hand-rolling validation
148
+
149
+ **Mistake:** Writing your own checks ("does this flow have a trigger?") inside Claude's response instead of calling `validate_flow`.
150
+
151
+ **Why it's wrong:** Your hand-rolled check will drift from the real validator. It will miss rules that the server checks (template syntax, custom-node version pinning, schema version compatibility). Worse, it gives a false sense of correctness.
152
+
153
+ **Do instead:** Always `validate_flow`. The server is authoritative.
154
+
155
+ ## AP14 — Unlabeled forms
156
+
157
+ **Mistake:** Adding `page` element children with empty `label` / `placeholder` / `content`. The form renders as a stack of identical grey rectangles with nothing telling the user what to fill in.
158
+
159
+ **Why it's wrong:**
160
+ - Users see three empty boxes and don't know what's being asked.
161
+ - Submission data is keyed by `label` (`{{form.submissionData["Your name"]}}`), so empty labels mean empty keys — downstream templates can't reference anything.
162
+ - It looks unprofessional and the user will complain ("the form is terrible").
163
+
164
+ **Do instead — every form MUST have:**
165
+
166
+ 1. A `textBlock` element FIRST (use `variant: "h2"` or `"h1"`) explaining what the form is for.
167
+ 2. Every input element with a **non-empty `label`** — short, action-oriented, unique within the form.
168
+ 3. Every input with a **`placeholder`** showing what valid input looks like (`"jane@example.com"`, not `"Enter email"`).
169
+ 4. **`required: true`** on fields that are actually required, with the rest left optional.
170
+ 5. **`width: "half"`** on pairs of short related fields (first/last name, email/phone) so they sit on one row.
171
+ 6. The submit button with a **meaningful `label`** (`"Send feedback"`, `"Get my quote"`) — not the default `"Continue"`.
172
+ 7. The right element TYPE per field — `email` for emails, `dropdown` for finite-option lists, `longText` only for genuinely multi-line input.
173
+
174
+ **Quick check before saving the page node:** ask yourself "if a stranger opened this form, would they know what to fill in without me explaining?" If no, the labels/headings are missing.
175
+
176
+ See Recipe 1 in `recipes.md` for a fully-fleshed example.
177
+
178
+ ## AP15 — Form without a submit button
179
+
180
+ **Mistake:** Building a `page` node with input elements but no `button` element. Users fill the form and have nowhere to click — the flow is stuck forever.
181
+
182
+ **Why it's wrong:** A page node advances to its `right` source handle only when the user presses a submit-action button. Without one, the page never completes. There is no implicit Continue button — *you must add one*. `validate_flow` raises `PAGE_MISSING_SUBMIT_BUTTON` for non-terminal pages without a `buttonAction: "submit"` button.
183
+
184
+ **Do instead:** Every non-terminal page MUST include at least one button element. The shape:
185
+
186
+ ```js
187
+ {
188
+ id: "submit",
189
+ type: "button",
190
+ buttonText: "Send feedback", // NOT `label` — the field is buttonText
191
+ buttonAction: "submit", // submit | link | stop | restart
192
+ buttonAlign: "left",
193
+ buttonColor: "#3b82f6",
194
+ }
195
+ ```
196
+
197
+ **Button action values (from `describe_page_element("button")`):**
198
+ - `submit` (default) — fires the page's `right` source handle and advances the flow. The typical Continue/Send button.
199
+ - `link` — opens `buttonLink` in same tab or new tab (`buttonLinkNewTab`). Does NOT advance the flow.
200
+ - `stop` — terminates the flow without advancing.
201
+ - `restart` — restarts the flow from the trigger.
202
+
203
+ **Terminal pages exemption:** pages with `isGoal: true` or `isExit: true` don't need a submit button (the flow has already terminated), though you may still want a `link` button ("Back to home") or a `restart` button ("Submit another").
204
+
205
+ ## AP16 — Button using `label` instead of `buttonText`
206
+
207
+ **Mistake:** `{type: "button", label: "Continue", action: "submit"}`.
208
+
209
+ **Why it's wrong:** The page renderer reads `buttonText` / `buttonAction` / `buttonAlign` / `buttonColor` / `buttonLink` / `buttonLinkNewTab`. The generic `label` / `action` keys from other element types do nothing on a button — your button shows the literal default text ("Continue") and uses the default action.
210
+
211
+ **Do instead:** Call `describe_page_element("button")` before adding a button element. Use the exact field names: `buttonText`, `buttonAction`, `buttonAlign`, `buttonColor`, `buttonLink`, `buttonLinkNewTab`, `width`.
212
+
213
+ ## AP17 — Wrong condition-logic key on `if` / `switch`
214
+
215
+ **Mistake:** Writing `data.conditionLogic: "and"` on an `if` node (or `"or"`).
216
+
217
+ **Why it's wrong:** The canvas and runtime read `logicOperator` (UPPERCASE `"AND"` or `"OR"`). `conditionLogic` was an early-release key that never landed in production. Lowercase values are also ignored — the toggle silently defaults to AND.
218
+
219
+ **Do instead:**
220
+ ```js
221
+ {type: "if", data: {
222
+ conditions: [...],
223
+ logicOperator: "OR", // UPPERCASE; "AND" or "OR" only
224
+ }}
225
+ ```
226
+
227
+ Same on `switch` cases: each case's `logicOperator` is uppercase.
228
+
229
+ ## AP18 — `aiSwitch` route using `contextDescription`
230
+
231
+ **Mistake:** Routes shaped as `{id, label, outputLabel, contextDescription: "..."}`.
232
+
233
+ **Why it's wrong:** The canvas Context textarea reads from `route.context`, NOT `route.contextDescription`. Writing the wrong key produces blank textareas in the editor — the routing prompt sees no context per route, so the LLM has nothing to discriminate on.
234
+
235
+ **Do instead:**
236
+ ```js
237
+ {type: "aiSwitch", data: {
238
+ routes: [
239
+ {id: "r1", label: "Refund", outputLabel: "Refund",
240
+ context: "User wants a refund — wording mentions money back, return, refund"},
241
+ ...
242
+ ]
243
+ }}
244
+ ```
245
+
246
+ Same when changing the credential, the canvas auto-derives `provider` and resets `model`. If you set `credentialId` programmatically, also set `provider` to the matching enum and pick a `model` valid for that provider.
247
+
248
+ ## AP19 — Terminal page using `goalName` only
249
+
250
+ **Mistake:** `{type: "page", data: {isGoal: true, goalName: "Signed up"}}`.
251
+
252
+ **Why it's wrong:** The canvas Goal picker reads `goalId` (FK to `end_conditions.goals[]`). When you write only `goalName`, the picker shows "Goal: (none selected)" — even though stats record the goal correctly, the editor UX is broken.
253
+
254
+ **Do instead:** Either:
255
+ - Reference an existing goal: set `goalId` AND `goalName` (matching the saved goal row).
256
+ - Or use a `goal` / `exit` node instead of the form-as-goal pattern.
257
+
258
+ Same with `isExit: true` — set both `exitId` and `exitName`.
259
+
260
+ ## AP20 — `httpRequest.authentication` missing `credential` type
261
+
262
+ **Mistake:** Reading the catalog and only seeing `none / bearer / basic / apikey` as auth types.
263
+
264
+ **Why it's wrong:** The production canvas defaults to `{type: "credential", credentialId: "<vault id>"}`. This references a saved Vault credential — the most common pattern. Don't write inline tokens if a Vault credential exists for the upstream API.
265
+
266
+ **Do instead:** `describe_node_type("httpRequest")` shows the full set. Prefer `type: "credential"` when the user has a Vault item set up for the API.
267
+
268
+ ## AP21 — Missing `claudeCode.retryConfig` / `offlineBehavior` / `fallbackSteps`
269
+
270
+ **Mistake:** Building a `claudeCode` node and assuming `onError: "stop"` is sufficient. The user later finds runs failing because their preferred Claude Code agent was offline.
271
+
272
+ **Why it's wrong:** `claudeCode` has three production-grade resiliency knobs that the catalog spells out: `offlineBehavior` ("error" or "queue" when agent offline), `retryConfig: {maxRetries, retryDelaySeconds}`, and `fallbackSteps[]` (an ordered list of backup agents with their own retries). If you don't configure them, you get the strict default (error immediately, no retry).
273
+
274
+ **Do instead:** For production workflows, set these explicitly. Example: queue if offline, retry twice, then fall back to a different agent:
275
+ ```js
276
+ {
277
+ type: "claudeCode",
278
+ data: {
279
+ agentId: "agent_primary",
280
+ offlineBehavior: "queue",
281
+ retryConfig: {maxRetries: 2, retryDelaySeconds: 30},
282
+ fallbackSteps: [{agentId: "agent_backup", waitSeconds: 60, retries: [{maxRetries: 1, retryDelaySeconds: 10}]}],
283
+ }
284
+ }
285
+ ```