Tips > Building Workflows

Use Execute Sub-Workflow for Reusable Utility Workflows

Utility sub-workflows are shared building blocks that multiple parent workflows can call.

Utility sub-workflows are shared building blocks that many parent workflows call, so common logic like a formatted Slack alert lives in one place instead of being duplicated across ten workflows. Define a standard input schema on the Execute Sub-Workflow Trigger, build the logic once, and call it everywhere; when the format changes you update a single workflow.

What is a utility sub-workflow?

Utility sub-workflows are shared building blocks that multiple parent workflows can call. Instead of duplicating the same Slack notification logic in 10 workflows, create one "Send Formatted Slack Alert" sub-workflow and call it from all of them. When you need to change the alert format, you update one workflow instead of ten.

Real-world example: A "Send Formatted Slack Alert" utility sub-workflow used by error handlers, monitoring workflows, and business process notifications.

How do you build a reusable sub-workflow?

Sub-workflow: "Slack - Send Formatted Alert - v2"

[Execute Sub-Workflow Trigger] → [Code: Build Block Kit] → [Slack: Send Message]

The trigger receives a standardized input schema:

{
  "severity": "info | warning | error | critical",
  "title": "Brief alert title",
  "message": "Detailed description",
  "source_workflow": "Name of the calling workflow",
  "fields": [
    { "label": "Customer", "value": "jane@acme.com" },
    { "label": "Order ID", "value": "ORD-12345" }
  ],
  "channel_override": null
}

Code node that builds the Slack Block Kit message:

const input = $json;

const severityConfig = {
  info:     { color: '#36a64f', icon: '[INFO]' },
  warning:  { color: '#ff9900', icon: '[WARNING]' },
  error:    { color: '#ff0000', icon: '[ERROR]' },
  critical: { color: '#8b0000', icon: '[CRITICAL]' }
};

const config = severityConfig[input.severity] || severityConfig.info;

const fields = (input.fields || []).map(f => ({
  type: 'mrkdwn',
  text: `*${f.label}:*\n${f.value}`
}));

const blocks = [
  {
    type: 'header',
    text: { type: 'plain_text', text: `${config.icon} ${input.title}` }
  },
  {
    type: 'section',
    text: { type: 'mrkdwn', text: input.message }
  }
];

if (fields.length > 0) {
  blocks.push({ type: 'section', fields: fields });
}

blocks.push({
  type: 'context',
  elements: [{
    type: 'mrkdwn',
    text: `Source: ${input.source_workflow} | ${new Date().toISOString()}`
  }]
});

const channel = input.channel_override || process.env.SLACK_CHANNEL || '#alerts';

return [{ json: { channel, blocks, color: config.color } }];

How do you call the sub-workflow from a parent?

Calling the sub-workflow from any parent:

// Execute Sub-Workflow node input mapping
{
  "severity": "error",
  "title": "Payment Processing Failed",
  "message": "Stripe returned a declined card error for order ORD-12345.",
  "source_workflow": "{{ $workflow.name }}",
  "fields": [
    { "label": "Customer", "value": "{{ $json.customer_email }}" },
    { "label": "Error", "value": "{{ $json.stripe_error }}" },
    { "label": "Amount", "value": "${{ $json.amount }}" }
  ]
}

Tip: Build a Utility Library Common utility sub-workflows to create: Slack alert, email with template, error logger, data validation, API authentication refresh, rate limiter. Tag them all with a "utility" tag for easy discovery.

Reusable sub-workflows enforce consistency and reduce the maintenance surface area of your workflow system.

Related: Always Set an Error Workflow on Every Production Workflow · Use "Pin Data" to Freeze Node Output

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

190 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book an introductory call