高级:结构化
机器翻译译自英文(docs.typesafe.ai)本页 27 段已全部译完
文档索引
在以下地址获取完整的文档索引:https://docs.typesafe.ai/llms.txt 使用此文件可以在进一步探索之前发现所有可用页面。
高级:结构化
说明(Instructions)、选项(Choice options)、评分等级(Score levels)和 Noul 准则(Noul criteria)均接受 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 格式有助于提高清晰度,因为键已命名。
- 问题需要支持数据时。 模式、分类法或数据库行本身已是 JSON。可以完全使用 JSON,或者传递相关的子字段,而不是将它们序列化为字符串模板。
结构化指令
单个 field 对象描述正在检查的字段,每个问题通过键引用它。相同的结构可驱动验证值的 Noul、从候选项中选择的 Choice,以及在量表上定位值的两个 Scores。
{
"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 规则
{
"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(选择),并在代码中遍历树。在每一步中,选项是当前节点的子节点,每个选项的值是子节点的树。这样做可以让模型在承诺选择某个分支之前,看到该分支下包含的内容,这对于属于叶节点且其名称不能仅从分支名称明显推断的项目来说至关重要。
此处状态为一个产品列表,第一个问题用于选择顶级部门。
{
"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(条件)仅是当前节点。Hierarchical Classification(层次分类)cookbook 展示了一个类似的树遍历示例,包括在概率相近时保留多个候选路径的束搜索(beam search)。
Note
子树可能会变得很大。如果分支过大,请将值修剪为其直接子节点和少量叶节点样本。
结构化 Score 级别
Score 的 criteria 数组中的每个条目都可以是一个对象。
{
"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 描述可以让你在每一侧通过定义和示例来确定边界。
{
"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"
]
}
}
}
}
}