Structured Output(结构化输出)是指让大语言模型按照预定义的JSON Schema或其他格式生成响应,而不是自由文本。这确保了输出的可预测性和可解析性,是Tool Calling和Agent系统可靠运行的基础。
自由文本虽然灵活,但机器难以可靠解析:
// ❌ 自由文本输出(难以解析)
"搜索结果:找到了3篇文章,第一篇是关于AI的,发表于2026年..."
// ✅ 结构化输出(机器可读)
{
"results": [
{"title": "AI发展报告", "date": "2026-06-17", "score": 0.95},
{"title": "Agent技术趋势", "date": "2026-06-16", "score": 0.87}
],
"total": 2
}
最基本的结构化输出,只保证输出是合法JSON:
// API调用
{
"model": "gpt-4o",
"response_format": { "type": "json_object" }
}
更严格的约束,输出必须符合指定的Schema:
// 定义Schema
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "number", "minimum": 0 },
"skills": { "type": "array", "items": { "type": "string" } }
},
"required": ["name", "age"]
}
// 模型输出保证符合这个Schema
OpenClaw 在多个场景使用结构化输出:
// 好的Schema设计
{
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["search", "create", "update", "delete"],
"description": "要执行的操作类型"
},
"target": {
"type": "string",
"description": "操作的目标对象"
},
"params": {
"type": "object",
"description": "操作参数",
"additionalProperties": true
}
},
"required": ["action", "target"]
}
← 返回术语百科首页
更多内容请访问 妙趣AI首页