Skip to main content
Last updated on

n8n Integration Guide

Reference for the OpenBox n8n integration — the governance pipeline, configuration options, error handling, and additional examples.

Just getting started?

Run the n8n Demo for a hands-on walkthrough, or Wrap an Existing n8n Workflow to add governance to your own workflow.

Prerequisites

Customising the Node

Change the LLM provider

Replace the Ollama call inside the activity callback. The SDK doesn't care what the activity does — it governs the data going in and coming out.

import { govern } from 'openbox';

const { output, meta } = await govern(
transport,
{ apiKey, activityType: 'OpenAIChat' },
'N8nChatWorkflow',
{ chatInput: userMessage },
async (governed) => {
const response = await helpers.httpRequest({
method: 'POST',
url: 'https://api.openai.com/v1/chat/completions',
headers: { Authorization: `Bearer ${openaiKey}` },
body: {
model: 'gpt-4o',
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: (governed as any).chatInput },
],
},
});
return { text: (response as any).choices[0].message.content };
},
);

Fail-closed governance

govern(transport, { apiKey, activityType, governancePolicy: 'fail_closed' }, ...);

Human-in-the-loop

govern(transport, { apiKey, activityType, hitlEnabled: true }, ...);

When governance returns require_approval, the SDK polls the dashboard until a human approves or rejects.

How It Works

govern() wraps your LLM call through a 5-stage pipeline:

Verdicts at each checkpoint:

VerdictBehavior
allowProceeds unmodified
constrainInput or output is redacted; call proceeds with cleaned data
require_approvalPauses until a human approves via the dashboard
blockTerminated, error returned
haltCall and enclosing workflow terminated

What gets checked at each stage is configured in the OpenBox Dashboard — no code changes needed.

Configuration Reference

Options passed to govern():

OptionDefaultDescription
apiKeyRequiredYour OpenBox API key (obx_live_* or obx_test_*)
apiEndpointhttps://core.openbox.aiOpenBox Core base URL
activityTypeLlmActivityMust match the dashboard config
governancePolicyfail_openSet to fail_closed to block when Core is unreachable
hitlEnabledfalseEnable human-in-the-loop approval
hitlPollInterval5Polling interval in seconds while waiting for approval
hitlMaxWait300Maximum wait time for approval in seconds
apiTimeout30Request timeout in seconds

Error Handling

When governance blocks a request, the user sees an error. Possible outcomes:

ErrorCause
GuardrailsValidationErrorInput or output failed a check (PII, toxicity, etc.)
GovernanceBlockedErrorA policy rule blocked the action
ApprovalExpiredErrorHITL request timed out
ApprovalRejectedErrorA human reviewer rejected the request
ApprovalDisabledErrorVerdict requires approval but HITL is not enabled

To catch these in code:

const {
GovernanceBlockedError,
GuardrailsValidationError,
ApprovalExpiredError,
ApprovalRejectedError,
ApprovalDisabledError,
} = require('openbox');

try {
const { output } = await govern(transport, config, workflow, input, callback);
} catch (err) {
if (err instanceof GuardrailsValidationError) { /* guardrail failed */ }
if (err instanceof GovernanceBlockedError) { /* policy blocked */ }
if (err instanceof ApprovalExpiredError) { /* HITL timed out */ }
if (err instanceof ApprovalRejectedError) { /* HITL rejected */ }
if (err instanceof ApprovalDisabledError) { /* HITL not enabled */ }
}

Next Steps

  1. Configure guardrails — PII detection, toxicity filtering, banned terms, content classification
  2. Set up policies — authorization rules, risk thresholds, data classification
  3. Enable approvals — human-in-the-loop workflows for sensitive operations
  4. View sessions — monitor governed interactions in the dashboard event timeline