Input contract for the workflow
Input contract for the workflow — AI n8n workflow: request to reviewed draft. Classify without sending; Create a reproducible item; Validate before inference. Practical assignment: Practice: Input contract for the workflow.
Demo edition. The materials are undergoing editorial review.
Topics covered
- Classify without sending
- Create a reproducible item
- Validate before inference
Classify without sending
The fictional workflow classifies a short request as support, billing or other, summarizes it and prepares a human-reviewed draft. It changes no CRM records and sends no email. Start with Manual Trigger, JavaScript fixtures and optionally local Ollama. No paid provider keys, OAuth or public webhook are needed. Define the boundary: the model proposes, code validates structure and a person decides the next action. Valid JSON alone establishes neither correct categorization nor permission to answer a customer.
Create a reproducible item
In a new unpublished workflow add Manual Trigger, then a Code node named Input in Run Once for All Items mode. The code returns one entirely fictional item. RequestId is a stable business identifier rather than an execution ID. Repeated tests of the same request preserve it so duplicate behavior can be examined. Real identifiers must come from a trusted source rather than model invention. Never use personal email as convenient fixture data in shared execution history.
// Code node: Input; Run Once for All Items.
return [{ json: {
requestId: 'lab-001',
text: 'Fictional request: please explain the duplicate invoice line.',
fixtureMode: true
}}];
Validate before inference
Add an InputCheck Code node. Missing identity, empty text or excessive length must stop before the HTTP request, reducing uncertainty, resource use and wrong-field processing. Do not use Continue On Fail to send invalid input toward an action branch. The lab deliberately handles one item; assert that assumption so a later batch cannot mix requests. Return only approved input fields. Never carry external approved, recipient or command fields into the next nodes as if they were trusted metadata.
// Code node: InputCheck; Run Once for All Items.
const items = $input.all();
if (items.length !== 1) throw new Error('one_item_required');
const x = items[0].json;
if (typeof x.requestId !== 'string' || !/^lab-[0-9]{3}$/.test(x.requestId)) throw new Error('invalid_id');
if (typeof x.text !== 'string' || !x.text.trim() || x.text.length > 1000) throw new Error('invalid_text');
return [{ json: { requestId: x.requestId, text: x.text.trim(), fixtureMode: x.fixtureMode === true } }];
Practical assignment
Practice: Input contract for the workflow
Continue to learning