Documentation
¶
Overview ¶
Guardrails node (@n8n/n8n-nodes-langchain.guardrails, versions 1 and 2).
The check logic — PII patterns, secret-key heuristics, URL filtering, keyword matching and the jailbreak / NSFW / topical-alignment prompts — is ported from openai-guardrails-js (https://github.com/openai/openai-guardrails-js, src/checks/*.ts at commit b9b99b4), Copyright (c) 2025 OpenAI, released under the MIT License (see THIRD_PARTY_NOTICES.md). The node interface (parameters, stages, outputs and item shapes) follows n8n's Guardrails node.
Package n8n runs n8n workflow definitions on the flow engine.
Every n8n node becomes one engine step. Data moves between steps in n8n's item model ([{json, binary, pairedItem}]) wrapped in port envelopes so that nodes with several outputs (IF, Switch, …) and several inputs (Merge) keep their n8n semantics.
Index ¶
- Constants
- func ActivationInputs(wf *models.Workflow, event string) []string
- func Register(reg *engine.Registry, opts *Options)
- func Supported(typ string) bool
- func UnregisterWebhooks(ctx context.Context, opts *Options, namespace string, wf *models.Workflow) error
- func WebhookKeys(wf *models.Workflow) []string
- type ChatMemoryReplacer
- type ChatMemoryStore
- type ChatMessage
- type CredentialNeed
- type CredentialProvider
- type CredentialRef
- type DataTable
- type DataTableColumn
- type DataTableStore
- type Handler
- type HandlerOptions
- type ImportOptions
- type Issue
- type Item
- type MemoryDataTables
- func (m *MemoryDataTables) GetDataTable(_ context.Context, ns, id string) (*DataTable, error)
- func (m *MemoryDataTables) ListDataTables(_ context.Context, ns string) ([]*DataTable, error)
- func (m *MemoryDataTables) UpdateDataTable(_ context.Context, ns, id string, fn func(*DataTable) (*DataTable, error)) error
- type NodeInput
- type Options
- type PollStateStore
- type PollStateSwapper
- type RateLimit
- type RateLimiter
- type Report
- type Runtime
- type Source
- type StaticCredentials
- type TriggerSpec
- type WebhookRegistration
- type WebhookRename
Constants ¶
const ( EventInstanceStarted = "init" EventWorkflowActivated = "activate" EventWorkflowUpdated = "update" )
n8n Trigger events and the event names n8n emits for them.
const CycleNodeType = "n8n:cycle"
CycleNodeType is the synthetic node that runs a cyclic region (e.g. a polling loop: IF -> Wait -> HTTP -> IF) of an imported n8n workflow.
const TriggerKey = "__trigger"
TriggerKey selects which trigger starts an execution: {"__trigger": "<node name or id>", "items": [...]}.
Variables ¶
This section is empty.
Functions ¶
func ActivationInputs ¶
ActivationInputs returns one execution input per n8n Trigger in wf that listens to event (EventInstanceStarted, EventWorkflowActivated or EventWorkflowUpdated), carrying n8n's event item.
func UnregisterWebhooks ¶
func UnregisterWebhooks(ctx context.Context, opts *Options, namespace string, wf *models.Workflow) error
UnregisterWebhooks deletes the webhooks RegisterWebhooks created.
func WebhookKeys ¶
WebhookKeys lists the HTTP routes a workflow's triggers claim ("METHOD path"), so hosts can reject conflicting installs.
Types ¶
type ChatMemoryReplacer ¶
type ChatMemoryReplacer interface {
Replace(ctx context.Context, sessionKey string, msgs []ChatMessage) error
}
ChatMemoryReplacer is an optional extension of ChatMemoryStore needed by the Chat Memory Manager's override-insert and delete modes.
type ChatMemoryStore ¶
type ChatMemoryStore interface {
Load(ctx context.Context, sessionKey string) ([]ChatMessage, error)
Append(ctx context.Context, sessionKey string, msgs ...ChatMessage) error
}
ChatMemoryStore keeps chat history for AI memory nodes.
type ChatMessage ¶
ChatMessage is one stored chat turn.
type CredentialNeed ¶
type CredentialNeed struct {
Node string `json:"node"`
Type string `json:"type"`
Name string `json:"name,omitempty"`
}
CredentialNeed is a credential the workflow requires.
type CredentialProvider ¶
type CredentialProvider interface {
Credential(ctx context.Context, namespace, credType string, ref CredentialRef) (map[string]interface{}, error)
}
CredentialProvider resolves n8n credentials for a namespace. The returned map holds the credential's fields as n8n defines them for its type, e.g. openAiApi: {"apiKey": "..."}, httpHeaderAuth: {"name": "...", "value": "..."}, any OAuth2 type: {"accessToken": "..."} (or n8n's {"oauthTokenData": {...}}).
type CredentialRef ¶
type CredentialRef struct {
ID string `json:"id"`
Name string `json:"name"`
WorkflowID string `json:"workflowId,omitempty"`
Node string `json:"node,omitempty"`
}
CredentialRef identifies a credential in an n8n node ({id, name}). The engine also fills in which workflow and node ask for it, so providers can enforce which workflows may use which credentials.
type DataTable ¶
type DataTable struct {
ID string `json:"id"`
Name string `json:"name"`
Columns []DataTableColumn `json:"columns"`
Rows []map[string]interface{} `json:"rows"`
NextRowID int64 `json:"nextRowId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
DataTable is one n8n Data Table: typed columns and rows. Rows hold the column values plus the system columns id, createdAt and updatedAt.
type DataTableColumn ¶
DataTableColumn is a column of a DataTable. Type is string, number, boolean or date.
type DataTableStore ¶
type DataTableStore interface {
ListDataTables(ctx context.Context, namespace string) ([]*DataTable, error)
GetDataTable(ctx context.Context, namespace, id string) (*DataTable, error)
UpdateDataTable(ctx context.Context, namespace, id string, fn func(t *DataTable) (*DataTable, error)) error
}
DataTableStore persists n8n Data Tables per namespace. UpdateDataTable must apply fn atomically (e.g. with a row lock or compare-and-swap): fn receives the current table (nil when it does not exist) and returns the table to store, or nil to delete it.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves n8n-style entry points for imported workflows:
{ANY} /webhook/{path} Webhook trigger (and Telegram/WhatsApp-style webhook triggers by webhookId)
POST /chat/{workflowID} Chat trigger: {"sessionId": "...", "chatInput": "..."}
POST /form/{workflowID} Form trigger: form fields as JSON or form-encoded
func NewHandler ¶
func NewHandler(eng *engine.Engine, n8nOpts *Options, opts HandlerOptions) *Handler
NewHandler returns the HTTP handler for a namespace.
type HandlerOptions ¶
type HandlerOptions struct {
// Namespace whose workflows are served.
Namespace string
// BaseURL is the public URL the handler is mounted at, exposed to
// workflows as $json.webhookUrl. Optional.
BaseURL string
// ResponseTimeout bounds how long synchronous responses (lastNode,
// responseNode, chat) wait for the workflow (default 2 minutes).
ResponseTimeout time.Duration
// MaxBodyBytes caps request bodies (default 16 MiB).
MaxBodyBytes int64
// RateLimit throttles webhook, chat, form and MCP requests (default: 600
// requests per minute per workflow, counted in process memory).
RateLimit RateLimit
// AuthorizeChat admits requests to chat triggers that are not public
// (the Chat Trigger's "Make Chat Publicly Available" is off, the n8n
// default): return true when r comes from your own signed-in chat UI,
// e.g. after checking its session or token. Nil serves only public
// chats; private ones answer 404, as in n8n.
AuthorizeChat func(r *http.Request, workflowID string) bool
// ForwardCookies passes the request's Cookie header to the workflow in
// $json.headers. Off by default: if the handler shares a domain with
// your app, a link to a workflow's webhook would hand the visitor's
// session cookie to the workflow's owner.
ForwardCookies bool
}
HandlerOptions configures the webhook/chat HTTP handler.
type ImportOptions ¶
type ImportOptions struct {
// ID of the resulting flow workflow. Defaults to the n8n workflow id, or
// a slug of its name.
ID string
// Name overrides the workflow name.
Name string
}
ImportOptions configures Import.
type Issue ¶
type Issue struct {
Node string `json:"node,omitempty"`
Type string `json:"type,omitempty"`
Message string `json:"message"`
}
Issue is a problem found while importing.
type Item ¶
type Item struct {
JSON map[string]interface{} `json:"json"`
Binary map[string]interface{} `json:"binary,omitempty"`
PairedItem interface{} `json:"pairedItem,omitempty"`
}
Item is one n8n data item.
func OutputItems ¶
OutputItems returns the items of an n8n step output, all ports in order. Hosts use it to read the result of an n8n execution.
type MemoryDataTables ¶
type MemoryDataTables struct {
// contains filtered or unexported fields
}
MemoryDataTables is a process-local DataTableStore.
func NewMemoryDataTables ¶
func NewMemoryDataTables() *MemoryDataTables
NewMemoryDataTables returns an empty in-memory DataTableStore.
func (*MemoryDataTables) GetDataTable ¶
GetDataTable implements DataTableStore.
func (*MemoryDataTables) ListDataTables ¶
ListDataTables implements DataTableStore.
func (*MemoryDataTables) UpdateDataTable ¶
func (m *MemoryDataTables) UpdateDataTable(_ context.Context, ns, id string, fn func(*DataTable) (*DataTable, error)) error
UpdateDataTable implements DataTableStore.
type NodeInput ¶
type NodeInput struct {
Inputs [][]Item
Sources [][]Source
// Raw is set when the node received a non-n8n input (trigger nodes
// receive the execution input as-is).
Raw string
}
NodeInput is the decoded input of one node execution.
type Options ¶
type Options struct {
// Timezone is the default zone for $now/DateTime when the workflow has no
// settings.timezone. Empty means the host's local zone.
Timezone string
// Env is exposed as $env. Empty by default: n8n blocks env access for
// untrusted workflows and so do we.
Env map[string]string
// ExpressionTimeout bounds each expression evaluation (default 5s).
ExpressionTimeout time.Duration
// CodeTimeout bounds each Code node run (default 60s).
CodeTimeout time.Duration
// JSMemoryLimit stops running JavaScript (expressions, Code nodes) when
// the process heap exceeds this many bytes. Zero uses 90% of the Go
// memory limit (GOMEMLIMIT) when one is set; negative disables it. goja
// cannot measure memory per run, so all runs over the limit stop.
JSMemoryLimit int64
// Credentials resolves n8n credential references. Nil means no
// credentials are available.
Credentials CredentialProvider
// Outbound restricts HTTP destinations of n8n nodes (SSRF protection).
Outbound node.OutboundPolicy
// ChatMemory stores conversation history for AI memory nodes. Nil uses a
// process-local in-memory store.
ChatMemory ChatMemoryStore
// WorkflowResolver maps an n8n workflow ID referenced by Execute
// Workflow / tool nodes to a flow workflow ID in the same namespace.
// Nil means IDs are used as-is.
WorkflowResolver func(n8nWorkflowID string) string
// APIBaseURLs overrides external API base URLs by service name
// ("telegram", "sheets", "gmail", "drive", "googleOAuth"), e.g. to route
// through an egress proxy or a test server.
APIBaseURLs map[string]string
// PollState stores polling trigger cursors (Gmail/Sheets/Drive
// triggers). Nil uses process memory; provide a durable store so polls
// resume correctly after restarts and across instances.
PollState PollStateStore
// ResumeBaseURL is the public URL the n8n handler is mounted at (e.g.
// "https://app.example.com/n8n"). With ResumeSecret it enables
// $execution.resumeUrl, send-and-wait approvals and multi-page forms.
ResumeBaseURL string
// ResumeSecret signs resume URLs (HMAC-SHA256). Keep it secret.
ResumeSecret string
// FileSystemRoot enables the Read/Write Files nodes, confined to this
// directory. Empty (default) disables file access.
FileSystemRoot string
// AllowLocalProcesses lets imported workflows start local processes:
// Execute Command, Python Code and STDIO MCP servers. Off by default;
// enable only for trusted workflows on isolated workers.
AllowLocalProcesses bool
// PythonPath is the interpreter for Python Code nodes (default python3).
PythonPath string
// DataTables stores n8n Data Tables. Nil uses a process-local in-memory
// store; provide a durable one for production.
DataTables DataTableStore
}
Options configures the n8n runtime.
type PollStateStore ¶
type PollStateStore interface {
GetPollState(ctx context.Context, key string) (string, bool, error)
SetPollState(ctx context.Context, key, value string) error
}
PollStateStore keeps the cursor of polling triggers (last seen message, row snapshot, …) between scheduled runs. Use a durable implementation in production; the default is process-local memory.
type PollStateSwapper ¶
type PollStateSwapper interface {
// CompareAndSwapPollState sets key to value only if its current value is
// old (or, when oldExists is false, only if key is absent).
CompareAndSwapPollState(ctx context.Context, key, old string, oldExists bool, value string) (bool, error)
}
PollStateSwapper is an optional extension of PollStateStore. When the store implements it, cursors are advanced with compare-and-swap so two overlapping polls (frequent schedules, several instances) never emit the same items twice: the poll that loses the swap emits nothing, and its window is picked up by the next poll. Without it, polls are only serialized within one process.
type RateLimit ¶
type RateLimit struct {
// PerWorkflow is how many requests per minute one workflow's routes
// accept from all callers together. Zero means 600; negative disables.
PerWorkflow int
// PerClient is how many requests per minute one client IP may send to
// the namespace's routes, unknown paths included. Zero disables. Behind
// a load balancer set ClientIP, or every caller shares the proxy's IP.
PerClient int
// ClientIP returns the caller's IP (e.g. from X-Forwarded-For as set by
// your trusted proxy). Nil uses the connection's remote address.
ClientIP func(r *http.Request) string
// Limiter keeps the counters. Nil keeps them in process memory, which
// limits each replica separately; use NewRedisRateLimiter to share them.
Limiter RateLimiter
}
RateLimit throttles the public entry points of N8NHandler (webhook, chat, form and MCP routes). Every request starts an execution, so without a limit anyone who knows a URL can fill the workers and spend the workflow owner's API credits.
type RateLimiter ¶
type RateLimiter interface {
Allow(ctx context.Context, key string, limit int, period time.Duration) (ok bool, retryAfter time.Duration, err error)
}
RateLimiter decides whether a request under key is within limit requests per period. When it is not, retryAfter says when the next one is.
func NewRedisRateLimiter ¶
func NewRedisRateLimiter(client redis.UniversalClient, prefix string) RateLimiter
NewRedisRateLimiter returns a RateLimiter whose counters live in Redis, so all replicas share one limit. Keys are prefix + the handler's key and expire on their own. It uses the Redis server clock.
type Report ¶
type Report struct {
// Runnable is true when every node and feature is supported; the
// workflow may still need credentials (see Credentials).
Runnable bool `json:"runnable"`
Nodes int `json:"nodes"`
Supported int `json:"supportedNodes"`
Blocking []Issue `json:"blocking,omitempty"`
Warnings []Issue `json:"warnings,omitempty"`
Credentials []CredentialNeed `json:"credentials,omitempty"`
Triggers []TriggerSpec `json:"triggers,omitempty"`
}
Report summarizes how well a workflow is supported.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime evaluates n8n expressions for one node execution.
type Source ¶
type Source struct {
Node string `json:"node"`
Port string `json:"port"`
Count int `json:"count"`
// Offset is the index of the first item within the source node's
// output (non-zero when a node runs on a single item of a batch).
Offset int `json:"offset,omitempty"`
}
Source describes a contiguous run of input items that came from one upstream node output.
type StaticCredentials ¶
type StaticCredentials struct {
// contains filtered or unexported fields
}
StaticCredentials is a simple in-memory CredentialProvider keyed by credential type and then by ID or name. Use it for tests and single-tenant setups; production hosts should back CredentialProvider with a vault.
func NewStaticCredentials ¶
func NewStaticCredentials() *StaticCredentials
NewStaticCredentials returns an empty StaticCredentials.
func (*StaticCredentials) Credential ¶
func (s *StaticCredentials) Credential(_ context.Context, _ string, credType string, ref CredentialRef) (map[string]interface{}, error)
Credential implements CredentialProvider.
func (*StaticCredentials) Set ¶
func (s *StaticCredentials) Set(credType, idOrName string, data map[string]interface{})
Set stores a credential under its type for the given ID or name. The special key "*" matches any reference of that type.
type TriggerSpec ¶
type TriggerSpec struct {
Node string `json:"node"`
Type string `json:"type"`
// Kind: manual | schedule | poll | webhook | chat | form | subworkflow | external
Kind string `json:"kind"`
Cron []string `json:"cron,omitempty"`
Path string `json:"path,omitempty"`
Method string `json:"method,omitempty"`
ResponseMode string `json:"responseMode,omitempty"`
Default bool `json:"default,omitempty"`
}
TriggerSpec describes how a workflow is started.
type WebhookRegistration ¶
type WebhookRegistration struct {
Node string `json:"node"`
Type string `json:"type"`
URL string `json:"url"`
// Manual is set when the service has no API for it: the URL must be
// entered in the service's settings (e.g. a Slack app's Event
// Subscriptions).
Manual bool `json:"manual,omitempty"`
Error string `json:"error,omitempty"`
}
WebhookRegistration reports the outcome for one service trigger.
func RegisterWebhooks ¶
func RegisterWebhooks(ctx context.Context, opts *Options, namespace string, wf *models.Workflow, baseURL string) []WebhookRegistration
RegisterWebhooks creates the webhooks of a workflow's service triggers in their services, pointing at baseURL + "/webhook/{webhookId}" (baseURL is where the n8n handler is publicly mounted). Registration data (webhook ids, signing secrets) is kept in Options.PollState.
type WebhookRename ¶
type WebhookRename struct {
Node string `json:"node"`
From string `json:"from"`
To string `json:"to"`
}
WebhookRename is a webhook route RenameWebhooks changed.
func RenameWebhooks ¶
func RenameWebhooks(data []byte, taken func(key string) bool, suffix string) ([]byte, []WebhookRename, error)
RenameWebhooks rewrites an n8n workflow export so its webhook routes do not collide: a Webhook node's path, or a Telegram/WhatsApp-style trigger's webhookId, that taken reports as used gets "-<suffix>" (then "-<suffix>-2", …) appended. It returns the rewritten export and what changed; an export with no taken route comes back unchanged.
Source Files
¶
- ai_llm.go
- ai_nodes.go
- ai_stores.go
- anthropic_vendor.go
- apify.go
- cheerio.go
- code.go
- code_helpers.go
- community_nodes.go
- conditions.go
- core_more.go
- creds.go
- cycles.go
- datatable.go
- drive.go
- email.go
- execdata.go
- expr.go
- files.go
- ftp.go
- gemini_vendor.go
- gmail.go
- google_more.go
- guardrails.go
- http.go
- http_pagination.go
- hubspot.go
- hubspot_fields.go
- imap.go
- importer.go
- integrations.go
- integrations_data.go
- integrations_microsoft.go
- integrations_misc.go
- integrations_web.go
- items.go
- jsmem.go
- langchain_code.go
- local_exec.go
- logic_nodes.go
- mcp_client.go
- mcp_server.go
- modules.go
- mongodb.go
- mssql.go
- node.go
- nodes_core.go
- perplexity.go
- poll_triggers.go
- polling.go
- pools.go
- rag.go
- ratelimit.go
- register.go
- rest_airtop.go
- rest_asana.go
- rest_brightdata.go
- rest_browseract.go
- rest_clickup.go
- rest_community.go
- rest_community2.go
- rest_connector.go
- rest_decodo.go
- rest_easybits.go
- rest_elevenlabs.go
- rest_evolutionapi.go
- rest_firecrawl.go
- rest_gitlab.go
- rest_googlebigquery.go
- rest_googlecloudstorage.go
- rest_googleslides.go
- rest_gotohuman.go
- rest_highlevel.go
- rest_htmlcsstoimage.go
- rest_htmlcsstopdf.go
- rest_hunter.go
- rest_klicktipp.go
- rest_linear.go
- rest_mailchimp.go
- rest_mattermost.go
- rest_mondaycom.go
- rest_nextcloud.go
- rest_pdfco.go
- rest_phantombuster.go
- rest_pipedrive.go
- rest_postiz.go
- rest_postwire.go
- rest_quickbooks.go
- rest_rapiwa.go
- rest_salesforce.go
- rest_scrapegraphai.go
- rest_sendinblue.go
- rest_serpapi.go
- rest_servicenow.go
- rest_sharepoint.go
- rest_shopify.go
- rest_small.go
- rest_snapshotsite.go
- rest_spotify.go
- rest_stripe.go
- rest_todoist.go
- rest_trello.go
- rest_uploadpost.go
- rest_uploadtourl.go
- rest_verifiemail.go
- rest_vlmrun.go
- rest_wave5a.go
- rest_wave5b.go
- rest_wave5c.go
- rest_xero.go
- rest_zendesk.go
- rest_zohocrm.go
- rest_zoom.go
- rest_zvid.go
- resume.go
- runner.go
- service_hook_register.go
- service_hook_specs.go
- service_hooks.go
- services.go
- services2.go
- services3.go
- sheets.go
- sheetwrite.go
- spreadsheet.go
- ssh.go
- telegram.go
- utility_nodes.go
- webhook.go
- xls.go
- youtube.go