Per-Route Conditional Field Contract Gate Before Append
Loading workflow…
Workflow Description
A fully local workflow that enforces a declared field contract inside each route before reports are appended. Manual Trigger plus a Code node emit eight fictional items for two routes (payments, logs); Set tags a stable routeId. A Code node validates every item only against its own route contract: always-required fields with accepted types plus conditional if-then rules (kind=transaction requires numeric amount, status=failed requires string errorCode). Results distinguish missing property, present-but-null and wrong type, and produce one summary per route with counts and per-rule compliance rates. If routes decisions, Set stamps them, Merge appends, and a final Code node emits one consolidated summary.
How it works
- 1.Manual Trigger starts the demo run.
- 2.Code emits 8 fictional route items, or passes through real items when provided.
- 3.Set adds a stable routeId with includeOtherFields enabled.
- 4.Code groups items by routeName and applies each route's own contract in isolation.
- 5.Per rule it counts applicable and compliant items, computes a compliance rate and records violations with recordId and issue type.
- 6.If sends passed=true route summaries to the accepted branch, others to the rejected branch.
- 7.Set in each branch adds a decision field while keeping the full report.
- 8.Merge in append mode concatenates both branches without unifying schemas.
- 9.Final Code node (runOnceForAllItems) returns exactly one consolidated summary item.
Use cases
- Guarantee each branch satisfies its mandatory and conditional fields before merging
- Validate transaction data where amount is required only for a specific kind
- Validate log data where errorCode is required only on failure
- Produce a field-quality report separating absence, null and type mismatch
Requirements
- n8n 2.49.x with core nodes only (no credentials)
- A stable routeName present on every item before validation
- Contract definitions maintained inside the Validate Per-Route Contracts node
- A recordId on each item so violations map back to their source
Setup and testing in n8n
- Import the JSON and open the workflow.
- Click Execute Workflow and inspect Build Final Gate Summary output.
- Confirm logs is accepted and payments is rejected due to PMT-002 (missing_field) and PMT-003 (wrong_type).
- Confirm PMT-005 (amount null with kind=fee) and LOG-003 (errorCode null with status=success) are not penalized because the antecedent is false.
- Make the emitter return an empty array and verify the 'empty input' report.
- Add an item with an unknown routeName and verify the missing_contract report.
Service Value
Ready-made workflow template for automation delivery and service execution.
Apps Used
Details
How to Use
- 1.Click "Download Template"
- 2.Open your n8n dashboard
- 3.Go to Workflows > Import from File
- 4.Select downloaded file and configure credentials
Nodes Used (9)
Stage 1 - Demo Data & Setup
Sticky Note
Stage 2 - Contract Gate
Sticky Note
Stage 3 - Routing & Append
Sticky Note
Run Contract Gate Demo
Manual Trigger
Emit Fictional Route Items
Code
Tag Route Identity
Set
Validate Per-Route Contracts
Code
Route Consensus Reached?
If
Mark Route Accepted
Set
Mark Route Rejected
Set
Append Route Reports
Merge
Build Final Gate Summary
Code
Fresh workflows, straight to your inbox
Get newly published DROPIDEA workflows, a clear overview of what they do, and a link to explore them.
- New workflows
- Clear overviews
- Setup guides