# Registry-based Classifier

> 基于规则的分类器：根据一组输入信号，使用确定性的加权评分算法，从注册表型 KnowledgeResource 中找出最匹配的条目。

Source: https://docs.sommatic.ai/zh/nodes/ai.classify.registry/

- 标识: `ai.classify.registry`
- 类别: AI
- 版本: 1.0.0
- 状态: 可用
- 执行方式: async

基于规则的分类器：根据一组输入信号，使用确定性的加权评分算法，从注册表型 KnowledgeResource 中找出最匹配的条目。

与依赖 LLM 选取标签的 `ai.classify` / `ai.classify.triage` 不同，该算子会针对调用方的信号，为结构化注册表（KR `resource_type: dataset`）中声明的每个候选条目打分，并返回得分最高的条目及其不透明的 `payload`，供下游节点直接使用（任务处理人、路由目标、SLA 提示、定价档位等）。

注册表结构和匹配语义完全与客户无关。注册表存放在 KnowledgeResource 中，因此非技术人员可以在 webapp 中增删改条目，而无需修改工作流图或重新部署编排器。

**如何作出决定**

每个条目通过 `match_rules` 声明三个相互独立的匹配通道：

- `labels`：与调用方 `labels[]` 信号做精确字符串匹配（例如分类输出 `"some_category.some_subcategory"`）。
- `tags`：与调用方 `tags[]` 信号做精确字符串匹配（例如上游分诊发出的路由提示）。
- `keywords`：与调用方 `text` 信号做不区分大小写的子串匹配（例如原始邮件或文档正文）。

每条规则都带有 `weight`。worker 遍历所有条目，累加命中规则的权重，并返回总分最高的条目。平分时按数组中的先后顺序取第一个（运维人员可通过调整行顺序显式表达优先级）。

若没有任何条目得分 > 0，worker 返回 `slug` 与注册表 `default_entry` 字段一致的条目（若注册表未设默认条目，则经由 `no_match` 端口退出）。

**典型适用场景**

- **受理路由**：从包含数百个分支/办公室/团队的注册表中为新案件分派去处，每个实体的处理人、SLA 和优先级都以数据形式声明。
- **工作量分派**：当选择取决于多个信号（类别 + 地区 + 紧急程度提示）时，从目录中挑选队列或专员。
- **产品/方案匹配**：依据分类结果和文本中的关键词，将支持工单匹配到具体的产品型号。
- **分级与筛选**：当判定标准的变化快于代码时，用规则把客户/线索分配到不同的等级、细分群体或工作流。

**为什么用专门的 worker，而不是 `flow.switch` 或 `data.transform`**

`flow.switch` 要求每种结果对应一个 case/端口，超过约 10 个 case 就难以扩展。`data.transform` 搭配内联 IIFE 会让评分代码在各个工作流中重复。`ai.classify.registry` 将算法集中管理，对注册表结构做防御性校验，并提供清晰的输入/输出契约，供下游节点（例如 `human.task.create`）通过表达式使用。

**何时不宜使用**

当决策需要语义理解（文本含义模糊、新颖案例、需要为人工审阅者写出理由）时，请改用 `ai.classify.triage`。该算子确定、可解释、运行成本低，但只有在声明了匹配关键词的情况下，才能应对新的表述方式。

## 配置

- `knowledge_resource_id` (string, 必填): KnowledgeResource（resource_type: dataset），其 `content.structured_data` 描述注册表：`{ version, default_entry?, entries: [{ slug, label, description?, match_rules: { labels, tags, keywords }, payload }] }`。在 webapp 的 `/cognitive-assets/knowledge-resource/*` 中管理。
- `labels` (array<string>, 可选): 用于与各条目 `match_rules.labels` 比对打分的分类标签。通常通过表达式设置，例如 `["{{ $json.category }}.{{ $json.subcategory }}"]`。每个元素都必须是精确匹配的字符串（不支持正则或部分匹配）。也可以传入单个字符串，会被转换为单元素数组。 默认值: `[]`.
- `tags` (array<string>, 可选): 用于与 `match_rules.tags` 比对打分的标签/提示信号。通常通过表达式设为上游分诊的 `routing_hints`，例如 `"{{ $json.routing_hints }}"`。精确字符串匹配。 默认值: `[]`.
- `text` (string, 可选): 用于与 `match_rules.keywords` 做不区分大小写子串匹配的文本。通常是规范化后的输入文本，例如 `"{{ $json.text }}"`。

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

## 输出端口

- `resolved` (默认): 已选定一个条目（真实匹配或已声明的默认条目）。
- `no_match`: 没有任何条目得分 > 0，且注册表未声明 `default_entry`。调用方必须显式处理这种未覆盖的情况。
- `error`: Error

## 输入契约

- `labels` (array | string, 可选): 分类标签（字符串数组或单个字符串）。
- `tags` (array | string, 可选): 标签/提示信号（字符串数组或单个字符串）。
- `text` (string, 可选): 用于关键词子串匹配的自由文本。

## 输出契约

- `entry` (object, 必填): 胜出的注册表条目，包含其不透明 payload 和匹配诊断信息。
  - `slug` (string, 必填)
  - `label` (string, 必填)
  - `description` (string | null, 可选)
  - `payload` (object, 必填): 条目上声明的不透明数据；使用方通过表达式读取。
  - `match` (object, 必填)
    - `score` (number, 必填)
    - `matched_reasons` (array<string>, 必填): 供审计的可读匹配原因，例如 `["label:foo(5)", "tag:bar(3)", "keyword:baz(1)"]`。使用默认回退条目时为空。
    - `is_default` (boolean, 必填): 没有任何条目得分 > 0 且触发了注册表 `default_entry` 时为 true。
- `registry_version` (integer | null, 可选): 注册表中 `structured_data.version` 的值，用于追溯。

## 在表达式中

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

- `$("Registry-based Classifier").item.json.entry` (object) = `{…}`: 胜出的注册表条目，包含其不透明 payload 和匹配诊断信息。
- `$("Registry-based Classifier").item.json.entry.slug` (string) = `"refund-request"`
- `$("Registry-based Classifier").item.json.entry.label` (string) = `"Refund request"`
- `$("Registry-based Classifier").item.json.entry.description` (string | null) = `"Customer asks for money back."`
- `$("Registry-based Classifier").item.json.entry.payload` (object) = `{…}`: 条目上声明的不透明数据；使用方通过表达式读取。
- `$("Registry-based Classifier").item.json.entry.match` (object) = `{…}`
- `$("Registry-based Classifier").item.json.entry.match.score` (number) = `8`
- `$("Registry-based Classifier").item.json.entry.match.matched_reasons` (array) = `[…] (2)`: 供审计的可读匹配原因，例如 `["label:foo(5)", "tag:bar(3)", "keyword:baz(1)"]`。使用默认回退条目时为空。
- `$("Registry-based Classifier").item.json.entry.match.is_default` (boolean) = `false`: 没有任何条目得分 > 0 且触发了注册表 `default_entry` 时为 true。
- `$("Registry-based Classifier").item.json.registry_version` (integer | null) = `3`: 注册表中 `structured_data.version` 的值，用于追溯。
- `$("Registry-based Classifier").item.json.port` (string) = `"resolved"` (编辑器不提示)


## 工作原理

确定性、无需模型的路由器：用加权规则把注册表数据集中的每个条目与给定的标签、标记和文本进行打分，返回得分最高的条目及其 payload。

1. 合并上游载荷与节点配置（以配置为准）；`knowledge_resource_id` 为空时抛出 `Missing 'knowledge_resource_id'`。`labels` 和 `tags` 接受数组（丢弃非字符串）或单个字符串。
2. 加载知识资源并读取 `content.structured_data`：`entries` 必须是数组；`default_entry` 和 `version` 可选。
3. 对每个条目：`match_rules.labels` 中出现在 `labels` 里的值、`match_rules.tags` 中出现在 `tags` 里的值（两者均精确匹配、区分大小写），以及在 `text` 中找到的 `match_rules.keywords` 值（子串匹配、不区分大小写），分别累加其 `weight`。缺失或非数字的权重按 1 计；负权重会扣分。
4. 保留得分大于 0 的条目并选出最高分；同分时取排在前面的条目。
5. 没有得分条目时，若 `default_entry` 指向存在的 slug，则以 `is_default: true`、得分 0 返回该条目；否则从 `no_match` 输出。

## 在工作流中

### 节点

```json
{
  "node_id": "node-route-request",
  "label": "Route request",
  "operator_slug": "ai.classify.registry",
  "operator_version": "1.0.0",
  "config": {
    "knowledge_resource_id": "<knowledge_resource_id>",
    "labels": [
      "{{ $json.category }}.{{ $json.subcategory }}"
    ],
    "tags": [
      "{{ $json.channel }}",
      "{{ $json.priority }}"
    ],
    "text": "{{ $json.text }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "port": "resolved",
    "entry": {
      "slug": "refund-request",
      "label": "Refund request",
      "description": "Customer asks for money back.",
      "payload": {
        "queue": "finance",
        "sla_hours": 24
      },
      "match": {
        "score": 8,
        "matched_reasons": [
          "label:billing.refund(5)",
          "keyword:reembolso(3)"
        ],
        "is_default": false
      }
    },
    "registry_version": 3
  },
  "port": "resolved"
}
```

## 输出端口 (代码中的行为)

### `resolved`

有条目得分大于 0，或使用了注册表的 `default_entry`。

```json
{
  "port": "resolved",
  "entry": {
    "slug": "refund-request",
    "label": "Refund request",
    "description": "Customer asks for money back.",
    "payload": {
      "queue": "finance",
      "sla_hours": 24
    },
    "match": {
      "score": 8,
      "matched_reasons": [
        "label:billing.refund(5)",
        "keyword:reembolso(3)"
      ],
      "is_default": false
    }
  },
  "registry_version": 3
}
```

### `no_match`

没有条目得分大于 0（或注册表为空），且没有有效的 `default_entry`。输出中不含 `entry`。

```json
{
  "port": "no_match",
  "registry_version": 3
}
```

### `error`

缺少资源 id、无法加载资源或其结构无效。

```json
{
  "error": "Invalid registry: 'content.structured_data.entries' must be an array"
}
```

## 代码中的行为

- `labels, tags, text`: 先从配置读取，再从上游载荷读取。匹配是字面匹配：不支持正则、不去空白，labels 和 tags 区分大小写。非字符串元素会被丢弃，因此数组中某个解析为数组的表达式元素会丢失；如需传入上游的整个列表，请把该键设为单个表达式，例如 `{{ $json.routing_hints }}`（运行时会解析为数组）。
- `execution`: 已声明但被忽略：worker 和引擎都不会读取该块中的 `retryOnFail`、`maxTries`、`waitBetweenTries`、`continueOnFail`、`alwaysOutputData` 或 `timeout_ms`。

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `Missing 'knowledge_resource_id'` | `error` | 未选择注册表数据集。 |
| `Invalid registry: 'content.structured_data.entries' must be an array` | `error` | 资源没有 `structured_data`，或其 `entries` 不是数组。请修正数据集内容。 |
| `Knowledge resource not found: <knowledge_resource_id>` | `error` | 该 id 不对应任何知识资源。已删除的资源会报 `Knowledge resource "<name>" has been deleted. Update the node config to reference an active resource.` |

## 说明与限制

- 不调用任何模型；结果只取决于注册表和输入，因此相同输入总会得到相同条目。
- worker 会把 `port` 放进结果中，因此下游 `$json.port` 为 `resolved` 或 `no_match`。`version` 不是数字时 `registry_version` 为 `null`。
- `entry.payload` 原样复制自注册表（不存在时为空对象）；可用 `{{ $json.entry.payload.queue }}` 之类的表达式读取路由数据。
- 每次运行都会从后端读取知识资源（超时 10 秒）。状态不是 `active` 的资源仍会被使用，并在日志中记录警告。


## 契约（JSON Schema）

### All (`*.definition.js`)

```json
{
  "slug": "ai.classify.registry",
  "name": "Registry-based Classifier",
  "category": "ai",
  "version": "1.0.0",
  "description": "Rule-based classifier that resolves the best-matching entry from a registry KnowledgeResource given a set of input signals, using a deterministic weighted-score algorithm.\n\nUnlike `ai.classify` / `ai.classify.triage` which rely on an LLM to pick a label, this operator scores each candidate entry declared in a structured registry (KR `resource_type: dataset`) against the caller's signals, and returns the highest-scoring entry along with its opaque `payload` — ready for downstream nodes to consume (task assignees, routing targets, SLA hints, pricing tiers, etc.).\n\nThe registry shape and matching semantics are fully client-agnostic. The registry lives in a KnowledgeResource so non-technical operators can add/edit/remove entries from the webapp without modifying the workflow graph or redeploying the orchestrator.\n\n**How it decides**\n\nEach entry declares `match_rules` with three independent channels:\n\n- `labels`: exact-string matches against the caller's `labels[]` signal (e.g. a classification output like `\"some_category.some_subcategory\"`).\n- `tags`: exact-string matches against the caller's `tags[]` signal (e.g. routing hints emitted by an upstream triage).\n- `keywords`: case-insensitive substring matches against the caller's `text` signal (e.g. the original email or document body).\n\nEach rule carries a `weight`. The worker iterates all entries, sums the weights of matching rules, and returns the entry with the highest total score. Ties break by first-in-array order (ops can reorder rows to express priority explicitly).\n\nIf no entry scores > 0, the worker returns the entry whose `slug` matches the registry's `default_entry` field (or exits via port `no_match` if the registry has no default).\n\n**Typical use cases**\n\n- **Intake routing**: classify an incoming case to a branch / office / team from a registry of hundreds of such entities, with per-entity assignee, SLA and priority declared as data.\n- **Workload dispatch**: pick a queue or specialist from a catalog when the choice depends on multiple signals (category + region + urgency hints).\n- **Product / plan selection**: match a support ticket to a product variant based on classification + keywords in the text.\n- **Tiering and filtering**: rule-based assignment of customers/leads to tiers, segments, or workflows when criteria evolve faster than code.\n\n**Why a dedicated worker instead of `flow.switch` or `data.transform`**\n\n`flow.switch` forces one case/port per outcome — doesn't scale past ~10 cases. `data.transform` with an inline IIFE duplicates the scoring code across workflows. `ai.classify.registry` centralizes the algorithm, validates the registry shape defensively, and exposes a clean input/output contract that downstream nodes (e.g. `human.task.create`) consume via expressions.\n\n**When NOT to use**\n\nWhen the decision requires semantic understanding (ambiguous text, novel cases, a justification written for a human reviewer), use `ai.classify.triage` instead. This operator is deterministic, explainable, and cheap to run — but it will only recover from novel phrasings if a matching keyword is declared.",
  "capabilities": [
    "ai",
    "classification",
    "routing",
    "rules",
    "deterministic",
    "registry",
    "explainability"
  ],
  "knowledge_binding": {
    "enabled": true,
    "resource_types": [
      "dataset"
    ],
    "field": "knowledge_resource_id",
    "label": "Registry Dataset"
  },
  "config_schema": {
    "type": "object",
    "required": [
      "knowledge_resource_id"
    ],
    "properties": {
      "knowledge_resource_id": {
        "type": "string",
        "title": "Registry Dataset",
        "description": "KnowledgeResource (resource_type: dataset) whose `content.structured_data` describes the registry: `{ version, default_entry?, entries: [{ slug, label, description?, match_rules: { labels, tags, keywords }, payload }] }`. Managed in the webapp at `/cognitive-assets/knowledge-resource/*`.",
        "x-ui-widget": "knowledge-resource-picker",
        "x-knowledge-resource-types": [
          "dataset"
        ]
      },
      "labels": {
        "type": "array",
        "title": "Label Signals",
        "description": "Classification labels to score against `match_rules.labels` of each entry. Typically set via expression, e.g. `[\"{{ $json.category }}.{{ $json.subcategory }}\"]`. Each element must be an exact string to match (no regex, no partial). Can also be provided as a single string, which is coerced to a one-element array.",
        "items": {
          "type": "string"
        },
        "default": []
      },
      "tags": {
        "type": "array",
        "title": "Tag Signals",
        "description": "Tag/hint signals to score against `match_rules.tags`. Typically set to the upstream triage's `routing_hints` via expression, e.g. `\"{{ $json.routing_hints }}\"`. Exact string match.",
        "items": {
          "type": "string"
        },
        "default": []
      },
      "text": {
        "type": "string",
        "title": "Free-form Text",
        "description": "Text used for case-insensitive substring matching against `match_rules.keywords`. Typically the normalized input text, e.g. `\"{{ $json.text }}\"`.",
        "default": ""
      },
      "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",
    "description": "Signals against which the registry entries are scored.",
    "properties": {
      "labels": {
        "type": [
          "array",
          "string"
        ],
        "description": "Classification labels (array of strings, or single string)."
      },
      "tags": {
        "type": [
          "array",
          "string"
        ],
        "description": "Tag/hint signals (array of strings, or single string)."
      },
      "text": {
        "type": "string",
        "description": "Free-form text for keyword substring matching."
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "entry": {
        "type": "object",
        "description": "Winning registry entry with its opaque payload and match diagnostics.",
        "properties": {
          "slug": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "payload": {
            "type": "object",
            "description": "Opaque data declared on the entry; consumers read this via expressions.",
            "additionalProperties": true
          },
          "match": {
            "type": "object",
            "properties": {
              "score": {
                "type": "number"
              },
              "matched_reasons": {
                "type": "array",
                "description": "Human-readable reasons for audit, e.g. `[\"label:foo(5)\", \"tag:bar(3)\", \"keyword:baz(1)\"]`. Empty when the default fallback is used.",
                "items": {
                  "type": "string"
                }
              },
              "is_default": {
                "type": "boolean",
                "description": "True when no entry scored > 0 and the registry's `default_entry` fired."
              }
            },
            "required": [
              "score",
              "matched_reasons",
              "is_default"
            ]
          }
        },
        "required": [
          "slug",
          "label",
          "payload",
          "match"
        ]
      },
      "registry_version": {
        "type": [
          "integer",
          "null"
        ],
        "description": "Value of `structured_data.version` from the registry, for traceability."
      }
    },
    "required": [
      "entry"
    ]
  },
  "ports": [
    {
      "port_id": "resolved",
      "label": "Resolved",
      "is_default": true,
      "description": "An entry was selected (either a real match, or the declared default)."
    },
    {
      "port_id": "no_match",
      "label": "No Match",
      "description": "No entry scored > 0 and the registry does not declare a `default_entry`. The caller must handle the uncovered case explicitly."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "classifier",
    "registry",
    "routing",
    "rule-based",
    "deterministic"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "required": [
    "knowledge_resource_id"
  ],
  "properties": {
    "knowledge_resource_id": {
      "type": "string",
      "title": "Registry Dataset",
      "description": "KnowledgeResource (resource_type: dataset) whose `content.structured_data` describes the registry: `{ version, default_entry?, entries: [{ slug, label, description?, match_rules: { labels, tags, keywords }, payload }] }`. Managed in the webapp at `/cognitive-assets/knowledge-resource/*`.",
      "x-ui-widget": "knowledge-resource-picker",
      "x-knowledge-resource-types": [
        "dataset"
      ]
    },
    "labels": {
      "type": "array",
      "title": "Label Signals",
      "description": "Classification labels to score against `match_rules.labels` of each entry. Typically set via expression, e.g. `[\"{{ $json.category }}.{{ $json.subcategory }}\"]`. Each element must be an exact string to match (no regex, no partial). Can also be provided as a single string, which is coerced to a one-element array.",
      "items": {
        "type": "string"
      },
      "default": []
    },
    "tags": {
      "type": "array",
      "title": "Tag Signals",
      "description": "Tag/hint signals to score against `match_rules.tags`. Typically set to the upstream triage's `routing_hints` via expression, e.g. `\"{{ $json.routing_hints }}\"`. Exact string match.",
      "items": {
        "type": "string"
      },
      "default": []
    },
    "text": {
      "type": "string",
      "title": "Free-form Text",
      "description": "Text used for case-insensitive substring matching against `match_rules.keywords`. Typically the normalized input text, e.g. `\"{{ $json.text }}\"`.",
      "default": ""
    },
    "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

```json
{
  "type": "object",
  "description": "Signals against which the registry entries are scored.",
  "properties": {
    "labels": {
      "type": [
        "array",
        "string"
      ],
      "description": "Classification labels (array of strings, or single string)."
    },
    "tags": {
      "type": [
        "array",
        "string"
      ],
      "description": "Tag/hint signals (array of strings, or single string)."
    },
    "text": {
      "type": "string",
      "description": "Free-form text for keyword substring matching."
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "entry": {
      "type": "object",
      "description": "Winning registry entry with its opaque payload and match diagnostics.",
      "properties": {
        "slug": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "payload": {
          "type": "object",
          "description": "Opaque data declared on the entry; consumers read this via expressions.",
          "additionalProperties": true
        },
        "match": {
          "type": "object",
          "properties": {
            "score": {
              "type": "number"
            },
            "matched_reasons": {
              "type": "array",
              "description": "Human-readable reasons for audit, e.g. `[\"label:foo(5)\", \"tag:bar(3)\", \"keyword:baz(1)\"]`. Empty when the default fallback is used.",
              "items": {
                "type": "string"
              }
            },
            "is_default": {
              "type": "boolean",
              "description": "True when no entry scored > 0 and the registry's `default_entry` fired."
            }
          },
          "required": [
            "score",
            "matched_reasons",
            "is_default"
          ]
        }
      },
      "required": [
        "slug",
        "label",
        "payload",
        "match"
      ]
    },
    "registry_version": {
      "type": [
        "integer",
        "null"
      ],
      "description": "Value of `structured_data.version` from the registry, for traceability."
    }
  },
  "required": [
    "entry"
  ]
}
```

### ports

```json
[
  {
    "port_id": "resolved",
    "label": "Resolved",
    "is_default": true,
    "description": "An entry was selected (either a real match, or the declared default)."
  },
  {
    "port_id": "no_match",
    "label": "No Match",
    "description": "No entry scored > 0 and the registry does not declare a `default_entry`. The caller must handle the uncovered case explicitly."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
