Safety Filter
依据安全准则评估文本,拦截有害内容。
实验性桩实现。它不评估输入,直接返回固定的 { message, timestamp } 对象且不带端口,因此引擎将其路由到此节点未声明的 out:连接到 safe 或 blocked 的节点都不会执行。
使用审核模型(例如 OpenAI Moderation API、Llama Guard)检测仇恨、骚扰、自残、色情或暴力等类别。
适用场景:
- 在发送给 LLM 之前审核用户输入。
- 在展示给用户之前校验 LLM 输出。
- 保障品牌安全。
工作原理
- 解析节点配置:配置键中的表达式会基于本次运行求值;传入条目按原样使用。
- 返回不带端口的
{ message: "Executed ai.safety.filter", timestamp }。引擎路由到out;由于没有out连线,该分支到此结束。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-safety-filter",
"label": "Moderate content",
"operator_slug": "ai.safety.filter",
"operator_version": "1.0.0",
"config": {
"policies": [
"hate",
"violence"
]
}
}{
"ok": true,
"port": "out",
"data": {
"message": "Executed ai.safety.filter",
"timestamp": "2026-11-26T15:04:05.000Z"
}
}配置
-
policiesarray<string> 可选 -
要拦截的类别列表(例如 ["hate", "violence"])。留空 = 全部。
配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
policies - 已声明但被忽略。
输出端口
safe 默认 永远不会触发。
blocked 永远不会触发:不会拦截任何内容。
error 代码从不输出此端口。
在表达式中
后续节点可通过 $("Safety Filter").item.json.<路径> 读取此节点输出中的内容,即工作流编辑器在 Previous Nodes 中提示的路径(输出契约)。
| 表达式 |
|---|
$("Safety Filter").item.json.is_safe |
$("Safety Filter").item.json.flagged_categories |
$("Safety Filter").item.json.scores |
输入契约
-
textstring 必填 -
需要审核的内容。
输出契约
-
is_safeboolean 可选 -
flagged_categoriesarray<string> 可选 -
scoresobject 可选
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "ai.safety.filter",
"name": "Safety Filter",
"category": "ai",
"version": "1.0.0",
"description": "Evaluates text against safety guidelines to block harmful content.\n\n Uses a moderation model (e.g., OpenAI Moderation API, Llama Guard) to detect categories like Hate, Harassment, Self-Harm, Sexual, or Violence.\n\n **Use Cases:**\n - Moderating user input before sending to an LLM.\n - Validating LLM output before showing to user.\n - Ensuring brand safety.",
"capabilities": [
"moderation",
"safety",
"guardrails"
],
"config_schema": {
"type": "object",
"properties": {
"policies": {
"type": "array",
"items": {
"type": "string"
},
"title": "Blocked Categories",
"description": "List of categories to block (e.g. [\"hate\", \"violence\"]). Empty = All."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
},
"input_contract_schema": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "Creating content to moderate."
}
},
"required": [
"text"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"is_safe": {
"type": "boolean"
},
"flagged_categories": {
"type": "array",
"items": {
"type": "string"
}
},
"scores": {
"type": "object"
}
}
},
"ports": [
{
"port_id": "safe",
"label": "Safe",
"is_default": true,
"description": "Content passed checks."
},
{
"port_id": "blocked",
"label": "Blocked",
"description": "Content violated safety policy."
},
{
"port_id": "error",
"label": "Error",
"description": "Moderation service failure."
}
],
"execution_mode": "async",
"tags": [
"safety",
"moderation",
"guardrail"
],
"is_stateful": false,
"publisher": {
"identity": "org_sommatic_ai",
"profile": {
"name": "Sommatic AI",
"verified": true,
"url": "https://me.veripass.com/sommatic",
"logo_url": null
}
}
}{
"type": "object",
"properties": {
"policies": {
"type": "array",
"items": {
"type": "string"
},
"title": "Blocked Categories",
"description": "List of categories to block (e.g. [\"hate\", \"violence\"]). Empty = All."
},
"execution": {
"type": "object",
"title": "Execution Settings",
"properties": {
"alwaysOutputData": {
"type": "boolean",
"title": "Always Output Data",
"description": "Always output data, even on error (if configured).",
"default": false
},
"retryOnFail": {
"type": "boolean",
"title": "Retry On Fail",
"description": "Retry the execution if it fails.",
"default": false
},
"maxTries": {
"type": "integer",
"title": "Max Retries",
"description": "Number of retries.",
"default": 3,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"waitBetweenTries": {
"type": "integer",
"title": "Wait Between Retries (ms)",
"default": 1000,
"displayOptions": {
"show": {
"retryOnFail": [
true
]
}
}
},
"continueOnFail": {
"type": "boolean",
"title": "Continue On Fail",
"description": "Do not crash workflow on error.",
"default": false
},
"timeout_ms": {
"type": "integer",
"title": "Timeout (ms)",
"description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
"default": 300000
}
}
}
}
}{
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "Creating content to moderate."
}
},
"required": [
"text"
]
}{
"type": "object",
"properties": {
"is_safe": {
"type": "boolean"
},
"flagged_categories": {
"type": "array",
"items": {
"type": "string"
}
},
"scores": {
"type": "object"
}
}
}[
{
"port_id": "safe",
"label": "Safe",
"is_default": true,
"description": "Content passed checks."
},
{
"port_id": "blocked",
"label": "Blocked",
"description": "Content violated safety policy."
},
{
"port_id": "error",
"label": "Error",
"description": "Moderation service failure."
}
]执行
- 执行方式
async- 有状态
- 否
- 重试(
retryOnFail) - 否
- 能力
moderationsafetyguardrails- 标签
safetymoderationguardrail
说明与限制
- 尚未实现:内容审核、分类得分和拦截。如需可用的安全检查,请使用路由到
pass/fail的ai.safety.scan。
已对照编排器代码核实 · 31e874b · 2026-11-26