原语(问题)进阶:结构

System One 模型经过训练,能够理解结构。

哪里可以使用结构

以下每个字段的类型都是 EntryType。

字段适用于接受的形态
instructionsChoice、Score、Noulstring、object、array 或 null
criteria 的值(选项描述)Choicestring、object、array 或 null
criteria 的条目(级别描述)Scorestring、object、array 或 null
criteria.true 和 criteria.falseNoulstring、object、array 或 null

什么时候该给问题加上结构

  • 当它有助于表达清晰时。 当一个问题由多个部分组成时,把它写成 JSON 形式有助于清晰,因为各个键都有标签。
  • 当问题需要辅助数据时。 schema、分类体系或数据库行本身就是 JSON。直接整体使用这份 JSON,或传入相关的子字段,而不是把它们序列化进字符串模板。

结构化 instructions

一个 field 对象描述被检查的字段,每个问题通过键引用它。同样的结构既驱动校验取值的 Noul,也驱动从候选中挑选的 Choice,还驱动把取值放到量表上的两个 Score。

request
json
{
  "state": {
    "source_text": "Invoice #4471 issued March 3, 2026 to Beaver Dam Logistics for $12,840.00, net 30."
  },
  "questions": {
    "invoice_number_is_correct": {
      "type": "noul",
      "instructions": {
        "field": {
          "name": "invoice_number",
          "type": "string",
          "description": "The identifier printed on the invoice."
        },
        "extracted_value": "4471",
        "question": "Does `extracted_value` match the `field` as it appears in `source_text`?"
      }
    },
    "customer_name": {
      "type": "choice",
      "instructions": {
        "field": {
          "name": "customer_name",
          "type": "string",
          "description": "The organization the invoice was issued to."
        },
        "question": "Which option is the value of `field` in `source_text`?"
      },
      "criteria": {
        "Beaver Logistics": null,
        "Dam Logistics": null,
        "Beaver Dam Logistics": null,
        "Beaver": null,
        "Dam": null
      }
    },
    "amount_due": {
      "type": "score",
      "instructions": {
        "field": {
          "name": "amount_due",
          "type": "number",
          "unit": "USD",
          "description": "The total the invoice asks to be paid."
        },
        "question": "How large is the `field` value in `source_text`?"
      },
      "criteria": [
        "Under $1,000",
        "$1,000 to $10,000",
        "$10,000 to $100,000",
        "$100,000 to $1,000,000",
        "Over $1,000,000"
      ]
    },
    "payment_terms": {
      "type": "score",
      "instructions": {
        "field": {
          "name": "payment_terms",
          "type": "integer",
          "unit": "days",
          "description": "Days allowed for payment, from terms such as \"net 30\"."
        },
        "question": "How many days does the `field` in `source_text` allow for payment?"
      },
      "criteria": [
        "Due on receipt",
        "Net 10",
        "Net 30",
        "Net 60",
        "Net 90"
      ]
    }
  }
}

在代码中,你可以遍历潜在的记录,为每个字段构造一个这样的问题,然后全部放进一次调用发送。结构化数据抽取级联实战手册做的就与此类似。

数组也可以。当 instruction 是一份要检查或要比对的内容清单时,可以使用数组:

json
"instructions": {
  "question": "Does the claimed sender identity conflict with the sending domain?",
  "compare": ["ticket.sender.display_name", "ticket.sender.email"],
  "focus": "Compare the named organization with the email domain."
}

结构化 Choice 选项

Choice 的选项描述同样可以是结构化对象。

用 JSON 评分标准澄清边界

request
json
{
  "state": "I ordered the standing desk two weeks ago and tracking still says label created. Was I even charged?",
  "questions": {
    "department": {
      "type": "choice",
      "instructions": {
        "question": "Which team should handle this message?",
        "focus": "Classify the customer's primary request, not every topic mentioned."
      },
      "criteria": {
        "billing": {
          "what": "Charges, invoices, refunds, or subscriptions",
          "not_for": "Order tracking or account access",
          "examples": [
            "I was charged twice",
            "Where is my refund?"
          ]
        },
        "orders": {
          "what": "Order status, delivery, cancellation, or returns",
          "not_for": "Charges or account access",
          "examples": [
            "Where is my package?",
            "Cancel my order"
          ]
        },
        "account": {
          "what": "Login, password, profile, or security",
          "not_for": "Charges or delivery",
          "examples": [
            "I can't log in",
            "Change my email"
          ]
        }
      }
    }
  }
}

这个示例告诉模型每个选项涵盖什么、不涵盖什么,从而锐化选项之间的边界。

遍历分类体系

要按深层分类体系做分类,每层问一个 Choice,并在代码中遍历这棵树。每一步的选项是当前节点的子节点,每个选项的值是该子节点的子树。这样模型在选定某个分支之前就能看到分支之下有什么;当条目所属的叶子仅凭分支名并不明显时,这一点很重要。

这里的状态是一条商品信息,第一个问题选择顶层部门。

request
json
{
  "state": "32oz plastic bottle with a flip straw lid. Fits most bike cages.",
  "questions": {
    "department": {
      "type": "choice",
      "instructions": "Which top-level department does this product belong to?",
      "criteria": {
        "Sporting Goods": {
          "Cycling": [
            "Bike Bottles & Cages",
            "Bike Lights",
            "Helmets"
          ],
          "Fitness": [
            "Yoga Mats",
            "Resistance Bands"
          ],
          "Outdoor": [
            "Tents",
            "Sleeping Bags",
            "Hydration Packs"
          ]
        },
        "Home & Kitchen": {
          "Drinkware": [
            "Water Bottles",
            "Travel Mugs",
            "Tumblers"
          ],
          "Cookware": [
            "Pots & Pans",
            "Bakeware"
          ]
        },
        "Baby & Toddler": [
          "Sippy Cups",
          "Bottle Warmers",
          "Bibs"
        ]
      }
    }
  }
}

这个瓶子放在两个部门下都说得通。展示子树让模型看到 Sporting Goods > Cycling > Bike Bottles & Cages 和 Home & Kitchen > Drinkware > Water Bottles 两条路径都存在,从而在“商品强调自行车水壶架”与“日常水杯”之间权衡。这个答案上的 probabilities 会告诉你两者的差距是否小到值得同时探索两个分支。

选定部门后,就用该部门的子节点作为选项、它们的子树作为值再问下一个 Choice,如此往复直到抵达叶子。在代码中,这可以是对嵌套字典的循环,每个问题的 criteria 就是当前节点。层级分类实战手册展示了一个类似的遍历树的例子,其中包括在概率接近时让多条候选路径并存的束搜索。

子树可能变得很大。如果某个分支过大,就把值裁剪为它的直接子节点和一部分叶子样本。

结构化 Score 级别

Score criteria 数组中的每一项都可以是对象。

request
json
{
  "state": "Fixed the null check in the payment handler. Also refactored the retry loop while I was in there, and bumped the SDK version since the old one had that timeout bug.",
  "questions": {
    "pr_scope": {
      "type": "score",
      "instructions": {
        "question": "How focused is this pull request description on a single change?",
        "note": "Judge the number of independent changes, not the size of any one change."
      },
      "criteria": [
        {
          "summary": "One change, clearly stated",
          "signals": [
            "A single fix or feature",
            "Nothing described as \"also\" or \"while I was in there\""
          ]
        },
        {
          "summary": "One main change plus a small related tweak",
          "signals": [
            "A primary change and one minor adjacent edit",
            "The tweak supports the main change"
          ]
        },
        {
          "summary": "Several independent changes bundled together",
          "signals": [
            "Two or more unrelated fixes or features",
            "Changes that could each be their own PR"
          ]
        }
      ]
    }
  }
}

结构化 Noul criteria

Noul 的 criteria 是可选的;当是/否边界比较微妙时,结构化的 true 和 false 描述让你可以用定义和两侧各自的示例把边界钉牢。

request
json
{
  "state": {
    "sender": {
      "display_name": "Beaver Dam Builders Ltd.",
      "email": "donotreply@payroll.example"
    },
    "message": "Your Q3 bonus is ready. Reply with your login password so we can verify your identity and release the funds."
  },
  "questions": {
    "requests_credentials": {
      "type": "noul",
      "instructions": {
        "question": "Does the `message` ask the recipient to disclose a sensitive credential?",
        "inspect": "message",
        "focus": "Look for a request to send the credential itself, not a request to change or reset it."
      },
      "criteria": {
        "true": {
          "what": "Asks the recipient to reply with, type, or send a password, PIN, one-time code, or other security sensitive answer",
          "examples": [
            "Reply with your password",
            "Send us the 6-digit code you just received"
          ]
        },
        "false": {
          "what": "No sensitive credential is requested",
          "examples": [
            "Reset your password from the settings page",
            "Your statement is ready"
          ]
        }
      }
    }
  }
}