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

Structured Multi-Pass Extraction

从文档中抽取一组预先声明的字段,并为每个字段返回值、模型自评置信度和文本出处,同时进行 schema 校验与重试。

以 Markdown 查看
在以下应用中打开
AI 可用 ai.legal.extract.structured-multi-pass 版本 1.0.0 执行方式: async

借助模型从文档中提取一组声明的字段,逐字段返回取值、自评置信度和出处引文;校验类型、必填项和允许值,并附带纠正信息重试。

专为多轮抽取流水线设计:长文档会被拆分为若干聚焦的轮次(例如身份识别、程序框架、时间线、当事人、受益人、日期)。每个节点只执行一轮,使用各自的 field_schema 和领域 system_instructions(学理规则和强信号规则写在提示词中,而不是放在 RAG 节点里)。

与基础实体抽取不同,该 worker 输出逐字段的遥测数据,适合人工复核和置信度把关:

value:抽取出的值(文档中未提及时为 null)。 confidence:模型自评的确定程度,取值范围 [0, 1]。 provenance:{ pass, source },即由哪一轮生成,以及发现该值的简短原文片段或章节引用。

抽取完成后,worker 会依据声明的字段 schema 校验结果(必填字段是否存在、基本类型、枚举取值)。若校验失败且仍有重试次数,则附带修正消息再次调用模型。它还会计算整体置信度,列出低于所配置阈值的字段,并路由到 low_confidence 端口,以便下游关卡(例如 hitl.approval.gate)请求人工复核。

与领域无关:完全由 field_schema + system_instructions 驱动,也可以通过 prompt_template_id 从可复用的 PromptTemplate 中预置这两项。

工作原理

  1. 合并上游载荷与节点配置(以配置为准)。text(或 input)必须是非空字符串,field_schema 至少要有一项带 name;否则返回 error。
  2. 以 system_instructions 构建说明;设置 prompt_template_id 时,模板的 system_instructions(或 template_body)会放在前面。模板不存在只记录日志。
  3. 发送系统提示词,逐项列出字段的类型、是否必填、strong_signals、do_not_confuse_with 和允许值,并要求返回 { fields: { <name>: { value, confidence, provenance } } }。用户消息为 # DOCUMENT + text,前面附上来自前序轮次的 context JSON(最多 8000 个字符);temperature: 0。
  4. 规范化每个声明的字段:置信度限制在 0–1,出处截断为 200 个字符并写成 { pass, source }。裸值的置信度为 0.5(为 null 时为 0);缺失字段设为 null、置信度 0。未声明的键会被丢弃。
  5. 校验必填字段、类型(number、boolean、array、object;string 和 date 总是通过)以及 enum。遇到无效 JSON 或校验错误时,把错误作为纠正信息再次调用模型,最多额外 max_retries 次(默认 1)。
  6. 把各字段置信度平均为 overall_confidence,列出低于 confidence_threshold 的字段;校验失败或有字段低于阈值时走 low_confidence,否则走 extracted。

在工作流中

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

{
  "node_id": "node-extract-ruling",
  "label": "Extract ruling data",
  "operator_slug": "ai.legal.extract.structured-multi-pass",
  "operator_version": "1.0.0",
  "config": {
    "text": "{{ $json.text }}",
    "pass_label": "identification",
    "field_schema": [
      {
        "name": "case_number",
        "type": "string",
        "required": true,
        "description": "Case reference number.",
        "strong_signals": "Case No., file number"
      },
      {
        "name": "ruling_date",
        "type": "date",
        "required": true,
        "description": "Date the ruling was issued."
      },
      {
        "name": "awarded_amount",
        "type": "number",
        "description": "Total amount ordered to be paid.",
        "do_not_confuse_with": "amounts claimed by the parties"
      }
    ],
    "system_instructions": "Read amounts as plain numbers without thousands separators.",
    "confidence_threshold": 0.7,
    "max_retries": 1,
    "language": "en",
    "llm_provider_id": "wf-llm-provider-xxxx",
    "invocation_mode": "stream",
    "timeout_ms": 120000
  }
}

配置

llm_provider_id string 必填

`LlmProviderModel` 记录的 `id`(例如 `wf-llm-provider-*`)。编排器将调用委托给后端:sync 模式调用 `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke`,stream 模式调用 SSE 流式端点。处理复杂法律文档时,请使用高质量的推理模型。

invocation_mode string 可选

LLM 调用的传输方式。`sync` 阻塞直到收到完整响应。`stream` 通过 SSE 逐步接收 token(对于单轮可能超过 30 秒的长文档,推荐使用)。默认为 `sync`。

默认值: sync

可选值: syncstream

timeout_ms integer 可选

每次 LLM 调用(含重试)的最长等待时间。sync 默认 30000,stream 默认 600000。

pass_label string 可选

本轮抽取的可读标识(例如 `identification`、`procedural-timeline`)。会写入每个字段的出处信息,以便下游合并/评分节点识别各个值由哪一轮生成。

默认值: pass-1

field_schema array<object> 必填

本轮必须抽取的字段。每一项声明一个字段。这是指示 LLM 填写的契约,也是校验结果的依据。

system_instructions string 可选

本轮的领域学理和规则(分类体系、制度规则、识别指引)。会原样嵌入系统提示词。抽取所需的知识放在这里,而不是放在 RAG 节点中。

prompt_template_id string 可选

可选的 `CognitiveInfrastructurePromptTemplateModel.id`。设置后,其 `system_instructions` 会置于内联 `system_instructions` 之前。非致命:若无法解析该模板,则使用内联指令。

confidence_threshold number 可选

自评置信度低于此值的字段会被标记,输出路由到 `low_confidence`。

默认值: 0.7

max_retries number 可选

schema 校验失败或 JSON 无法解析时,附带修正消息重新调用模型的次数。

默认值: 1

language string 可选

文档及响应所使用的语言。

默认值: es

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

代码中的行为

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

field_schema
每项包括:name(必填)、type(默认 string)、description、required(只有 true 才算)、strong_signals、do_not_confuse_with、enum。enum 采用严格相等比较。
max_retries
首次之后的额外尝试次数(默认 1,即最多 2 次模型调用)。每次重试都会重新发送文档,只附带最新的纠正信息,不附带上一次回答。
prompt_template_id
以 10 秒超时从后端获取;不存在或获取失败时只使用 system_instructions。
text, context
不在配置 schema 中,但会先从配置读取,再从上游载荷读取。context 必须是对象,以 JSON 发送并截断为 8000 个字符。
timeout_ms
分别作用于每次模型调用,且仅在 stream 模式下生效(片段间空闲超时)。
execution
已声明但被忽略:worker 和引擎都不会读取该块中的 retryOnFail、maxTries、waitBetweenTries、continueOnFail、alwaysOutputData 或 timeout_ms。

输出端口

extracted 默认

校验通过,且所有字段都不低于 confidence_threshold。

数据
{
  "fields": {
    "case_number": {
      "value": "2025-00418",
      "confidence": 0.96,
      "provenance": {
        "pass": "identification",
        "source": "Case No. 2025-00418"
      }
    },
    "ruling_date": {
      "value": "2026-03-14",
      "confidence": 0.9,
      "provenance": {
        "pass": "identification",
        "source": "Issued on 14 March 2026"
      }
    },
    "awarded_amount": {
      "value": 18500,
      "confidence": 0.82,
      "provenance": {
        "pass": "identification",
        "source": "orders payment of 18,500"
      }
    }
  },
  "pass_label": "identification",
  "overall_confidence": 0.8933333333333332,
  "low_confidence_fields": [],
  "validation": {
    "valid": true,
    "errors": []
  },
  "field_count": 3
}
low_confidence

有字段低于阈值,或重试后校验仍失败。会返回最后一次解析出的字段,供审核人员补全。

数据
{
  "fields": {
    "case_number": {
      "value": "2025-00418",
      "confidence": 0.96,
      "provenance": {
        "pass": "identification",
        "source": "Case No. 2025-00418"
      }
    },
    "ruling_date": {
      "value": null,
      "confidence": 0,
      "provenance": {
        "pass": "identification",
        "source": null
      }
    }
  },
  "pass_label": "identification",
  "overall_confidence": 0.48,
  "low_confidence_fields": [
    "ruling_date"
  ],
  "validation": {
    "valid": false,
    "errors": [
      "Missing required field: ruling_date"
    ]
  },
  "field_count": 2
}
error

没有文本或字段 schema、所有尝试都返回无法解析的 JSON,或某次模型调用失败。

数据
{
  "error": "Extraction produced no usable fields.",
  "validation": {
    "valid": false,
    "errors": [
      "LLM did not return parseable JSON"
    ]
  }
}

在表达式中

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

表达式EditorWorker
$("Structured Multi-Pass Extraction").item.json.fieldsobject= {…}逐字段结果:以字段名为键的 { value, confidence, provenance: { pass, source } }。
$("Structured Multi-Pass Extraction").item.json.pass_labelstring= "identification"生成这些字段的轮次。
$("Structured Multi-Pass Extraction").item.json.overall_confidencenumber= 0.8933333333333332所有已声明字段自评置信度的平均值。
$("Structured Multi-Pass Extraction").item.json.low_confidence_fieldsarray= […] (0)置信度低于阈值的字段名。
$("Structured Multi-Pass Extraction").item.json.validationobject= {…}Schema 校验结果 { valid, errors[] }。
$("Structured Multi-Pass Extraction").item.json.field_countnumber= 3本轮声明的字段数量。
$("Structured Multi-Pass Extraction").item.json.fields.case_numberobject编辑器不提示= {…}—
$("Structured Multi-Pass Extraction").item.json.fields.ruling_dateobject编辑器不提示= {…}—
$("Structured Multi-Pass Extraction").item.json.fields.awarded_amountobject编辑器不提示= {…}—
$("Structured Multi-Pass Extraction").item.json.validation.validboolean编辑器不提示= true—
$("Structured Multi-Pass Extraction").item.json.validation.errorsarray编辑器不提示= […] (0)—

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

错误

消息 端口 原因与处理
Missing 'text' to extract from. error text 为空或不是字符串(此节点不会把上游载荷对象当作文本)。
No field schema provided. Set 'field_schema' (array of field definitions). error field_schema 不是数组,或没有任何带 name 的项。
Extraction produced no usable fields. error 所有尝试返回的文本都无法解析为 JSON;data.validation 中为最后一次的错误。
[LegalExtractStructuredMultipass] 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>。

输入契约

text string 必填

文档全文(例如来自 ai.multimodal.extract.text.cascade-pipeline)。

context object 可选

可选的前几轮结果,作为上下文向后传递以提高一致性。

输出契约

fields object 可选

逐字段结果:以字段名为键的 `{ value, confidence, provenance: { pass, source } }`。

pass_label string 可选

生成这些字段的轮次。

overall_confidence number 可选

所有已声明字段自评置信度的平均值。

low_confidence_fields array<string> 可选

置信度低于阈值的字段名。

validation object 可选

Schema 校验结果 `{ valid, errors[] }`。

field_count number 可选

本轮声明的字段数量。

契约(JSON Schema)

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

{
  "slug": "ai.legal.extract.structured-multi-pass",
  "name": "Structured Multi-Pass Extraction",
  "category": "ai",
  "version": "1.0.0",
  "description": "Extract a declared set of fields from a document and, for EVERY field, return value + self-assessed confidence + textual provenance, with schema validation and retry.\n\n  Designed for multi-pass extraction pipelines where a long document is split into focused passes (e.g. identification, procedural framework, timeline, actors, beneficiaries, dates). Each node runs ONE pass with its own `field_schema` and domain `system_instructions` (the doctrine/strong-signal rules live in the prompt, not in a RAG node).\n\n  Unlike basic entity extraction, this worker produces per-FIELD telemetry suitable for human review and confidence gating:\n\n  **value** — the extracted value (null when not stated in the document).\n  **confidence** — the model's self-assessed certainty in [0, 1].\n  **provenance** — `{ pass, source }`: which pass produced it and a short verbatim snippet/section reference where it was found.\n\n  After extraction the worker validates the result against the declared field schema (required fields present, basic types, enum membership). If validation fails and retries remain, it re-invokes the model with a correction message. It also scores overall confidence and lists fields below the configured threshold, routing to the `low_confidence` port so a downstream gate (e.g. `hitl.approval.gate`) can request human review.\n\n  Domain-neutral: drive it entirely from `field_schema` + `system_instructions`, or seed those from a reusable PromptTemplate via `prompt_template_id`.",
  "capabilities": [
    "nlp",
    "extraction",
    "legal",
    "structured",
    "confidence",
    "provenance",
    "multi-pass"
  ],
  "config_schema": {
    "type": "object",
    "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 the SSE stream endpoint for stream mode. Use a high-quality reasoning model for complex legal documents.",
        "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 (recommended for long documents where a pass may run >30s). Default `sync`.",
        "enum": [
          "sync",
          "stream"
        ],
        "default": "sync"
      },
      "timeout_ms": {
        "type": "integer",
        "title": "Timeout (ms)",
        "description": "Maximum time to wait for each LLM call (including retries). Default 30000 for sync, 600000 for stream.",
        "minimum": 1000
      },
      "pass_label": {
        "type": "string",
        "title": "Pass Label",
        "default": "pass-1",
        "description": "Human-readable identifier for this extraction pass (e.g. `identification`, `procedural-timeline`). Stamped into each field's provenance so downstream merge/scoring nodes can tell which pass produced each value."
      },
      "field_schema": {
        "type": "array",
        "title": "Field Schema",
        "description": "The fields this pass must extract. Each item declares one field. This is the contract the LLM is instructed to fill and the result is validated against.",
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "title": "Field Name",
              "description": "Output key for the field."
            },
            "type": {
              "type": "string",
              "title": "Type",
              "enum": [
                "string",
                "number",
                "boolean",
                "array",
                "object",
                "date"
              ],
              "default": "string",
              "description": "Expected value type, used for validation."
            },
            "description": {
              "type": "string",
              "title": "Description",
              "description": "What this field represents."
            },
            "required": {
              "type": "boolean",
              "title": "Required",
              "default": false,
              "description": "Fail validation if missing."
            },
            "strong_signals": {
              "type": "string",
              "title": "Strong Signals",
              "description": "Textual cues that indicate where to find this field (embedded in the prompt)."
            },
            "do_not_confuse_with": {
              "type": "string",
              "title": "Do Not Confuse With",
              "description": "Disambiguation guidance to avoid common extraction mistakes."
            },
            "enum": {
              "type": "array",
              "title": "Allowed Values",
              "description": "Optional closed set of allowed values, enforced during validation.",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "name"
          ]
        }
      },
      "system_instructions": {
        "type": "string",
        "title": "System Instructions",
        "description": "Domain doctrine and rules for this pass (taxonomies, regime rules, detection guidance). Embedded verbatim into the system prompt. This is where extraction knowledge lives instead of a RAG node.",
        "x-ui-widget": "textarea"
      },
      "prompt_template_id": {
        "type": "string",
        "title": "Prompt Template",
        "description": "Optional `CognitiveInfrastructurePromptTemplateModel.id`. When set, its `system_instructions` are prepended to the inline `system_instructions`. Non-fatal: if the template cannot be resolved, the inline instructions are used.",
        "ui_widget": "prompt_template_picker"
      },
      "confidence_threshold": {
        "type": "number",
        "title": "Confidence Threshold",
        "default": 0.7,
        "minimum": 0,
        "maximum": 1,
        "description": "Fields with self-assessed confidence below this value are flagged and route output to `low_confidence`."
      },
      "max_retries": {
        "type": "number",
        "title": "Max Retries",
        "default": 1,
        "minimum": 0,
        "description": "How many times to re-invoke the model with a correction message when schema validation fails or JSON is unparseable."
      },
      "language": {
        "type": "string",
        "title": "Language",
        "default": "es",
        "description": "Language of the document and the response."
      },
      "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
          }
        }
      }
    },
    "required": [
      "llm_provider_id",
      "field_schema"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "Full text of the document (e.g. from ai.multimodal.extract.text.cascade-pipeline)."
      },
      "context": {
        "type": "object",
        "description": "Optional results from prior passes, carried forward as context to improve coherence."
      }
    },
    "required": [
      "text"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "fields": {
        "type": "object",
        "description": "Per-field result: `{ value, confidence, provenance: { pass, source } }` keyed by field name."
      },
      "pass_label": {
        "type": "string",
        "description": "The pass that produced these fields."
      },
      "overall_confidence": {
        "type": "number",
        "description": "Mean self-assessed confidence across declared fields."
      },
      "low_confidence_fields": {
        "type": "array",
        "description": "Field names with confidence below the threshold.",
        "items": {
          "type": "string"
        }
      },
      "validation": {
        "type": "object",
        "description": "Schema validation result `{ valid, errors[] }`."
      },
      "field_count": {
        "type": "number",
        "description": "Number of declared fields in this pass."
      }
    }
  },
  "ports": [
    {
      "port_id": "extracted",
      "label": "Extracted",
      "description": "All fields valid and at/above the confidence threshold.",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "low_confidence",
      "label": "Low Confidence",
      "description": "Extraction succeeded but some fields are below threshold or failed validation — route to a review gate.",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Extraction failed (no text, no schema, or no parseable output).",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "nlp",
    "extraction",
    "legal",
    "structured",
    "confidence",
    "provenance",
    "xai"
  ],
  "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)
否
能力
nlpextractionlegalstructuredconfidenceprovenancemulti-pass
标签
ainlpextractionlegalstructuredconfidenceprovenancexai

说明与限制

  • 可串联多轮提取:每轮设置各自的 pass_label 和 field_schema,并把前序结果作为 context 传入;provenance.pass 会记录每个值由哪一轮产出。
  • 置信度和出处均为模型的自我声明;代码不会核实引文是否确实存在于文档中。
  • language 默认为 es,只决定回答语言说明行。
  • 模型调用经由 Sommatic AI 后端完成,后端根据 llm_provider_id 指定的提供方记录解析端点、凭据和部署;编排器从不持有提供方密钥。invocation_mode: "sync"(默认)等待完整回答;"stream" 以 SSE 事件读取回答并拼接各片段。
  • 在 stream 模式下,后端端点不应用采样参数,因此固定的 temperature: 0 仅在 sync 模式下生效。
  • 只有校验相关的重试:模型调用本身失败(网络、提供方)不会重试,直接走 error。

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

安装智能体工具

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

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

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