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

Enrich Data

使用 LLM 为记录添加计算得出、推断得出或经过标准化的字段,从而增强数据。

以 Markdown 查看
在以下应用中打开
AI 可用 ai.enrich 版本 1.0.0 执行方式: async

借助模型向 JSON record 添加所需的 output_fields(categorize、standardize、infer 或 augment),全部字段都添加成功时走 success,否则走 partial。

选择一种增强模式并定义所需的输出字段。该算子读取输入记录,应用所选策略,返回增强后的记录,并为每个字段附带置信度得分。

操作:

  • Categorize: 根据记录内容为其添加类别标签。
  • Standardize: 将姓名、地址、日期和电话号码规范为一致的格式。
  • Infer: 根据可用上下文推理,补全缺失的字段值。
  • Augment: 添加计算字段,例如根据职位推断资历、根据公司名称推断所属行业。

工作原理

  1. 合并上游载荷与节点配置(以配置为准),读取必须为对象的 record;output_fields 不能为空。
  2. 设置了 input_fields 时只保留记录中这些键;否则把完整记录格式化后作为用户消息发送。
  3. 设置了 knowledge_resource_id 时,把资源 content 以 JSON 形式追加到 Reference data for lookup: 下;获取失败只记录日志。
  4. 发送模式说明,逐项列出输出字段 - name (type): description,并要求严格 JSON;temperature: 0.1。
  5. 将回答解析为 JSON,其中必须含 enriched_record。若 output_fields 中所有名称都出现在 added_fields 中则走 success,否则走 partial。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-enrich-lead",
  "label": "Enrich lead",
  "operator_slug": "ai.enrich",
  "operator_version": "1.0.0",
  "config": {
    "record": "{{ $json.lead }}",
    "enrichment_mode": "augment",
    "input_fields": [
      "company",
      "title"
    ],
    "output_fields": [
      {
        "name": "industry",
        "type": "string",
        "description": "Industry of the company."
      },
      {
        "name": "seniority",
        "type": "string",
        "description": "Seniority implied by the job title."
      }
    ],
    "language": "en",
    "llm_provider_id": "wf-llm-provider-xxxx",
    "invocation_mode": "sync"
  }
}

配置

llm_provider_id string 可选

`LlmProviderModel` 记录的 `id`(例如 `wf-llm-provider-*`)。编排器将调用委托给后端:sync 模式调用 `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke`,stream 模式调用 `POST /chat/conversation/execute/stream-ephemeral`(SSE)。后端根据该记录解析 endpoint + api-key + deployment,并路由到相应的适配器。

invocation_mode string 可选

LLM 调用的传输方式。`sync` 会阻塞直到收到完整响应。`stream` 通过 SSE 逐步接收 token(长文本生成必须使用)。默认为 `sync`。

默认值: sync

可选值: syncstream

timeout_ms integer 可选

等待调用完成的最长时间(stream 模式下为分块之间的空闲超时)。sync 默认 30000,stream 默认 600000。

enrichment_mode string 必填

要应用的策略:分类、标准化、推断缺失值或补充计算字段。

默认值: categorize

可选值: categorizestandardizeinferaugment

input_fields array<string> 可选

要读取输入记录中的哪些字段。

output_fields array<object> 必填

要在增强后的记录中添加或计算的字段。

knowledge_resource_id string 可选

可选:用于增强的参考数据或查找表。

language string 可选

输入数据的语言。

默认值: en

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

代码中的行为

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

record
不在配置 schema 中(位于输入契约中),但会先从配置读取,再从上游载荷读取。
enrichment_mode
未知值会使用 categorize 的说明。
input_fields
过滤模型可见的字段,但会要求模型在 enriched_record 中返回原始字段;被过滤掉的字段不会由代码合并回来。
timeout_ms
仅限 stream 模式:片段之间的空闲超时,默认 600000。在 sync 模式下不会作用于请求。
execution
已声明但被忽略:worker 和引擎都不会读取该块中的 retryOnFail、maxTries、waitBetweenTries、continueOnFail、alwaysOutputData 或 timeout_ms。

输出端口

success 默认

模型在 added_fields 中列出了所有请求的字段。

数据
{
  "enriched_record": {
    "company": "Northwind Logistics",
    "title": "Head of Operations",
    "industry": "Logistics",
    "seniority": "Director"
  },
  "added_fields": [
    "industry",
    "seniority"
  ],
  "confidence_per_field": {
    "industry": 0.93,
    "seniority": 0.81
  }
}
partial

added_fields 中至少缺少一个请求的字段。

数据
{
  "enriched_record": {
    "company": "Northwind Logistics",
    "title": "Head of Operations",
    "industry": "Logistics"
  },
  "added_fields": [
    "industry"
  ],
  "confidence_per_field": {
    "industry": 0.93
  }
}
error

缺少记录或输出字段、模型调用失败或回答缺少 enriched_record。

数据
{
  "error": "Model did not return valid enrichment output."
}

在表达式中

后续节点可通过 $("Enrich Data").item.json.<路径> 读取此节点输出中的内容(请把 Enrich Data 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 success 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Enrich Data").item.json.enriched_recordobject= {…}合并了新字段的原始记录。
$("Enrich Data").item.json.added_fieldsarray= […] (2)成功添加的字段名列表。
$("Enrich Data").item.json.confidence_per_fieldobject= {…}每个新增字段的置信度得分(0-1)。
$("Enrich Data").item.json.enriched_record.companystring编辑器不提示= "Northwind Logistics"—
$("Enrich Data").item.json.enriched_record.titlestring编辑器不提示= "Head of Operations"—
$("Enrich Data").item.json.enriched_record.industrystring编辑器不提示= "Logistics"—
$("Enrich Data").item.json.enriched_record.senioritystring编辑器不提示= "Director"—
$("Enrich Data").item.json.confidence_per_field.industrynumber编辑器不提示= 0.93—
$("Enrich Data").item.json.confidence_per_field.senioritynumber编辑器不提示= 0.81—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
Missing or invalid input record. error record 不存在或不是对象。
At least one output field must be defined. error output_fields 为空。
Model did not return valid enrichment output. error 回答不是 JSON 或缺少 enriched_record。
[AiEnrich] Missing 'llm_provider_id' in node config (LlmProviderModel.id, e.g. 'wf-llm-provider-*'). The legacy 'model_id' alias is no longer supported — update the node config to use 'llm_provider_id'. error llm_provider_id 为空或不是字符串。请选择具备 chat 能力的 LLM 提供方记录。
LLM Invocation Error: <backend message> error 后端拒绝了调用:提供方记录不存在或未激活、提供方报错、配额或内容过滤。请检查提供方记录和后端日志。
LLM Invocation Error: empty response from backend (<transport error>) error sync 模式:对后端的 HTTP 调用失败(网络错误、非 2xx 状态或超时)。长提示词常会触发请求超时,请改用 invocation_mode: "stream"。
RemoteApiService.stream: idle timeout after <timeout_ms>ms error stream 模式:在 timeout_ms 内未收到任何片段。若流式请求本身失败,消息为 RemoteApiService.stream: HTTP <status> — <body>。

输入契约

record object 必填

要增强的数据记录。

context string 可选

用于提高增强准确度的可选上下文。

输出契约

enriched_record object 可选

合并了新字段的原始记录。

added_fields array 可选

成功添加的字段名列表。

confidence_per_field object 可选

每个新增字段的置信度得分(0-1)。

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "ai.enrich",
  "name": "Enrich Data",
  "category": "ai",
  "version": "1.0.0",
  "description": "Enrich records by adding computed, inferred, or standardized fields using an LLM.\n\n  Select an enrichment mode and define the output fields you need. The operator reads the input record, applies the chosen strategy, and returns the enriched record with confidence scores per field.\n\n  **Operations:**\n  - **Categorize:** Add category tags to a record based on its content.\n  - **Standardize:** Normalize names, addresses, dates, and phone numbers to consistent formats.\n  - **Infer:** Fill missing field values by reasoning from available context.\n  - **Augment:** Add computed fields such as seniority from job title or industry from company name.",
  "capabilities": [
    "ai",
    "enrichment",
    "data-quality",
    "augmentation"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "enrichment_mode",
      "output_fields"
    ],
    "properties": {
      "llm_provider_id": {
        "type": "string",
        "title": "LLM Provider",
        "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
        "x-ui-widget": "llm-provider-picker",
        "x-llm-provider-capabilities": [
          "chat"
        ]
      },
      "invocation_mode": {
        "type": "string",
        "title": "Invocation Mode",
        "description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
        "enum": [
          "sync",
          "stream"
        ],
        "default": "sync"
      },
      "timeout_ms": {
        "type": "integer",
        "title": "Timeout (ms)",
        "description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
        "minimum": 1000
      },
      "enrichment_mode": {
        "type": "string",
        "title": "Enrichment Mode",
        "enum": [
          "categorize",
          "standardize",
          "infer",
          "augment"
        ],
        "default": "categorize",
        "description": "Strategy to apply: categorize, standardize, infer missing values, or augment with computed fields."
      },
      "input_fields": {
        "type": "array",
        "title": "Input Fields",
        "items": {
          "type": "string"
        },
        "description": "Which fields from the input record to read."
      },
      "output_fields": {
        "type": "array",
        "title": "Output Fields",
        "description": "Fields to add or compute in the enriched record.",
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "description": "Field name to produce."
            },
            "description": {
              "type": "string",
              "description": "What this field represents."
            },
            "type": {
              "type": "string",
              "description": "Expected data type (string, number, boolean, array)."
            }
          }
        }
      },
      "knowledge_resource_id": {
        "type": "string",
        "title": "Knowledge Resource",
        "description": "Optional: reference data or lookup tables for enrichment.",
        "ui_widget": "knowledge_resource_picker"
      },
      "language": {
        "type": "string",
        "title": "Language",
        "default": "en",
        "description": "Language of the input data."
      },
      "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": {
      "record": {
        "type": "object",
        "description": "The data record to enrich."
      },
      "context": {
        "type": "string",
        "description": "Optional context to improve enrichment accuracy."
      }
    },
    "required": [
      "record"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "enriched_record": {
        "type": "object",
        "description": "Original record merged with new fields."
      },
      "added_fields": {
        "type": "array",
        "description": "List of field names successfully added."
      },
      "confidence_per_field": {
        "type": "object",
        "description": "Confidence score (0-1) for each added field."
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Enriched",
      "description": "All requested fields were added successfully.",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "partial",
      "label": "Partial",
      "description": "Some requested fields could not be computed.",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Enrichment failed.",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "enrichment",
    "data-quality",
    "augmentation"
  ],
  "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)
否
能力
aienrichmentdata-qualityaugmentation
标签
aienrichmentdata-qualityaugmentation

说明与限制

  • enriched_record 完全取自模型返回值;代码不会与输入记录合并,也不校验字段类型。输入中的 context 会被忽略。
  • 该 worker 在 data 旁返回 raw;引擎只把 data 存为节点输出,因此下游无法读取 raw。
  • 模型调用经由 Sommatic AI 后端完成,后端根据 llm_provider_id 指定的提供方记录解析端点、凭据和部署;编排器从不持有提供方密钥。invocation_mode: "sync"(默认)等待完整回答;"stream" 以 SSE 事件读取回答并拼接各片段。
  • timeout_ms 仅在 stream 模式下生效,表示片段之间允许的最长空闲时间(默认 600000)。在 sync 模式下该值只写入日志,不会作用于 HTTP 请求,因此以平台默认请求超时为准。
  • 在 stream 模式下,后端端点不应用采样参数,因此固定的 temperature: 0.1 仅在 sync 模式下生效。
  • 每次运行都会从后端读取知识资源(超时 10 秒)。状态不是 active 的资源仍会被使用,并在日志中记录警告。
  • 不会自动重试:引擎不会为本节点执行 execution.retryOnFail、maxTries 或 waitBetweenTries;调用失败会直接从 error 输出。

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

安装智能体工具

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

安装 Sommatic AI CLI,并为检测到的智能体配置合适的插件。

npx @sommatic/cli agent setup
智能体如何读取本文档