结构化输出
结构化输出可降低解析成本,适合信息抽取、工作流编排和自动化入库。
推荐方式
- 使用 JSON Schema 限制字段
- 服务端再次校验格式
- 对缺失字段给出回退策略
示例
json
{
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "summary_result",
"schema": {
"type": "object",
"properties": {
"title": { "type": "string" },
"keywords": { "type": "array", "items": { "type": "string" } },
"score": { "type": "number" }
},
"required": ["title", "keywords"]
}
}
}
}失败处理
- 解析失败时回退到纯文本并记录样本。
- 高风险任务增加二次生成与比对。