Redact PII
对文本或 JSON 对象中的个人身份信息(PII)进行脱敏,保障数据隐私与合规。
用正则表达式遮盖或删除节点输入项中的个人信息:默认处理电子邮件和银行卡号;在 rules 中列出时,还可处理美式 SSN、电话号码格式或自定义模式。
工作原理
- 以节点输入项(上一个节点的输出)作为脱敏内容。节点上配置的
input字段不会被使用。 - 将输入项序列化为 JSON 字符串。
- 按顺序应用
rules中的每一项:预设名称(email、credit_card、ssn、phone),否则把文本编译为带g标志的正则表达式。无效模式会被静默跳过。 - 将每个匹配替换为与其等长的
*(strategy: "mask",默认),或替换为空("remove")。 - 将字符串解析回 JSON,并在
result中从out返回。
在工作流中
节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。
{
"node_id": "node-redact-ticket",
"label": "Redact ticket PII",
"operator_slug": "pii.redact",
"operator_version": "1.0.0",
"config": {
"input": "{{ $json }}",
"strategy": "mask",
"rules": [
"email",
"credit_card",
"phone"
]
}
}{
"ok": true,
"port": "out",
"data": {
"result": {
"customer": "Jane",
"email": "****************",
"card": "*******************",
"note": "call ************"
}
}
}配置
-
inputobject 必填 -
要脱敏的文本或 JSON 对象
-
strategystring 可选 -
rulesarray 可选 -
正则表达式或预定义类型
代码中的行为
除 schema 描述之外,实现代码对这些键的实际处理。
-
input - 会被忽略:运行时用节点输入项替换它。若只需脱敏部分数据,请先用前置节点(如
data.transform)整理输入项。 -
rules - 默认值为
["email", "credit_card"]:ssn和phone只有列出时才会应用。预设:email(local@domain.tld)、credit_card(16 位数字,分为四组,每组四位,可用-或空格分隔)、ssn(123-45-6789)、phone(10 位数字,如555-123-4567、555.123.4567或5551234567;不含国家代码、括号或空格)。模式只检查格式,不做校验位验证。自定义模式区分大小写,并作用于序列化后的 JSON,因此也会匹配对象的键名。 -
strategy - 除
remove外的任何值都按遮盖处理。遮盖保留原始长度;remove会在匹配处留下空字符串。
输出端口
out 默认 输入项已脱敏并解析回 JSON。
数据
{
"result": {
"customer": "Jane",
"email": "****************",
"card": "*******************",
"note": "call 555-123-4567"
}
}error rules 不是数组,或替换破坏了序列化后的 JSON。
数据
{
"error": "rules.forEach is not a function"
}在表达式中
后续节点可通过 $("Redact PII").item.json.<路径> 读取此节点输出中的内容(请把 Redact PII 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Redact PII").item.json.result脱敏后的内容 | ||
$("Redact PII").item.json.result.customer | — | |
$("Redact PII").item.json.result.email | — | |
$("Redact PII").item.json.result.card | — | |
$("Redact PII").item.json.result.note | — |
— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。
错误
| 消息 | 端口 | 原因与处理 |
|---|---|---|
rules.forEach is not a function | error | rules 是字符串或对象。请传入数组,例如 ["email", "phone"]。 |
Unexpected token '*', "<serialized item>" is not valid JSON | error | 模式匹配到了 JSON 数字(例如存为 5551234567 的电话号码)或 JSON 语法(引号、花括号、冒号),导致文本无法解析。请把此类值存为字符串,或让自定义模式只匹配值的内容。错误信息中会包含序列化输入项的片段。 |
输入契约
-
inputobject 必填 -
strategystring 可选 -
rulesarray 可选
输出契约
-
resultobject 可选 -
脱敏后的内容
契约(JSON Schema)
与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。
{
"slug": "pii.redact",
"name": "Redact PII",
"category": "identity",
"version": "1.0.0",
"description": "Redacts Personally Identifiable Information (PII) from text or JSON objects to ensure data privacy and compliance.",
"capabilities": [
"privacy",
"dlp"
],
"config_schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"description": "Text or JSON Object to redact"
},
"strategy": {
"type": "string",
"enum": [
"mask",
"remove"
],
"default": "mask"
},
"rules": {
"type": "array",
"default": [
"email",
"credit_card"
],
"description": "Regex or Predefined Types"
}
},
"required": [
"input"
]
},
"input_contract_schema": {
"type": "object",
"properties": {
"input": {
"type": "object"
},
"strategy": {
"type": "string"
},
"rules": {
"type": "array"
}
},
"required": [
"input"
]
},
"output_contract_schema": {
"type": "object",
"properties": {
"result": {
"type": "object",
"description": "Redacted content"
}
}
},
"ports": [
{
"port_id": "out",
"label": "Redacted",
"description": "Clean data",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Processing failed",
"is_default": false,
"supports_condition": false
}
],
"execution_mode": "sync",
"required_resources": [],
"compatible_worker_pools": [
"standard"
],
"tags": [
"pii",
"compliance"
],
"is_stateful": false,
"publisher": {
"identity": "org_veripass",
"profile": {
"name": "Veripass",
"verified": true,
"url": "https://me.veripass.com/veripass",
"logo_url": null
}
}
}{
"type": "object",
"properties": {
"input": {
"type": "object",
"description": "Text or JSON Object to redact"
},
"strategy": {
"type": "string",
"enum": [
"mask",
"remove"
],
"default": "mask"
},
"rules": {
"type": "array",
"default": [
"email",
"credit_card"
],
"description": "Regex or Predefined Types"
}
},
"required": [
"input"
]
}{
"type": "object",
"properties": {
"input": {
"type": "object"
},
"strategy": {
"type": "string"
},
"rules": {
"type": "array"
}
},
"required": [
"input"
]
}{
"type": "object",
"properties": {
"result": {
"type": "object",
"description": "Redacted content"
}
}
}[
{
"port_id": "out",
"label": "Redacted",
"description": "Clean data",
"is_default": true,
"supports_condition": true
},
{
"port_id": "error",
"label": "Error",
"description": "Processing failed",
"is_default": false,
"supports_condition": false
}
]执行
- 执行方式
sync- 有状态
- 否
- 能力
privacydlp- 标签
piicompliance
说明与限制
- 只会处理列出的模式:姓名、地址、其他格式的身份证件号以及 15 位卡号会原样通过。
- 从
error端口输出不会使运行失败:引擎沿error上的连线继续;若没有连线,该分支直接结束。
已对照编排器代码核实 · 31e874b · 2026-11-26