本页内容
Sommatic 文档
打开控制台

Safety Filter

依据安全准则评估文本,拦截有害内容。

以 Markdown 查看
在以下应用中打开
AI 实验性 ai.safety.filter 版本 1.0.0 执行方式: async

实验性桩实现。它不评估输入,直接返回固定的 { message, timestamp } 对象且不带端口,因此引擎将其路由到此节点未声明的 out:连接到 safe 或 blocked 的节点都不会执行。

使用审核模型(例如 OpenAI Moderation API、Llama Guard)检测仇恨、骚扰、自残、色情或暴力等类别。

适用场景:

  • 在发送给 LLM 之前审核用户输入。
  • 在展示给用户之前校验 LLM 输出。
  • 保障品牌安全。

工作原理

  1. 解析节点配置:配置键中的表达式会基于本次运行求值;传入条目按原样使用。
  2. 返回不带端口的 { 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"
    ]
  }
}

配置

policies array<string> 可选

要拦截的类别列表(例如 ["hate", "violence"])。留空 = 全部。

配置中会显示通用执行设置,但该节点目前不执行重试(retryOnFail、maxTries)。所有节点均未实现 continueOnFail。

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

policies
已声明但被忽略。

输出端口

safe 默认

永远不会触发。

blocked

永远不会触发:不会拦截任何内容。

error

代码从不输出此端口。

在表达式中

后续节点可通过 $("Safety Filter").item.json.<路径> 读取此节点输出中的内容,即工作流编辑器在 Previous Nodes 中提示的路径(输出契约)。

表达式
$("Safety Filter").item.json.is_safeboolean
$("Safety Filter").item.json.flagged_categoriesarray
$("Safety Filter").item.json.scoresobject

输入契约

text string 必填

需要审核的内容。

输出契约

is_safe boolean 可选
flagged_categories array<string> 可选
scores object 可选

契约(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
    }
  }
}

执行

执行方式
async
有状态
否
重试(retryOnFail)
否
能力
moderationsafetyguardrails
标签
safetymoderationguardrail

说明与限制

  • 尚未实现:内容审核、分类得分和拦截。如需可用的安全检查,请使用路由到 pass/fail 的 ai.safety.scan。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档