文档导航

进阶:结构

进阶:结构

instructions、Choice 选项、Score 档位和 Noul 判定标准,都接受 JSON 结构。

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

哪些字段允许使用结构

下面这些字段,每一个都是 EntryType。

字段 适用于 接受的形态
instructions Choice、Score、Noul string、object、array 或 null
criteria 的值(选项描述) Choice string、object、array 或 null
criteria 的条目(档位描述) Score string、object、array 或 null
criteria.true 和 criteria.false Noul string、object、array 或 null

什么时候该给问题加结构

  • 当结构有助于说清楚时。 一个问题包含多个部分时,把它们写成 JSON 的形式会更清楚,因为每个键都有名字。
  • 当问题需要附带数据时。 一份 schema、一套分类法、一行数据库记录,本身就是 JSON。直接整份用,或者只传相关的子字段,不要把它们序列化进字符串模板里。

结构化的 instructions

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

request
{
  "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"
      ]
    }
  }
}

在代码里,你可以遍历可能存在的记录,为每个字段各构建一个这样的问题,全部放进一次调用里发出。SDE 级联 cookbook 做的就是类似的事。

数组也可以。当指令是一串要检查或要比较的东西时,就用数组:

"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
{
  "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
{
  "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,如此重复,直到走到叶子。在代码里,这可以是对一个嵌套 dict 的循环,每个问题的 criteria 就是当前节点。分层分类 cookbook 给了一个类似遍历树的例子,其中还包括一个束搜索:当概率咬得很近时,让几条候选路径同时活着。

结构化的 Score 档位

Score 的 criteria 数组里,每个条目都可以是一个对象。

request
{
  "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 判定标准

Noul 的 criteria 是可选的。当是/非的边界很微妙时,结构化的 true 和 false 描述能让你给每一边都加上定义和例子,把边界钉死。

request
{
  "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"
          ]
        }
      }
    }
  }
}