Skip to content

结构化输出 ​

通过 JSON Schema 约束模型输出,减少解析失败和字段漂移。

JSON Schema ​

json
{
  "model": "gpt-5.5",
  "messages": [{"role": "user", "content": "提取订单号和金额"}],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "order",
      "schema": {
        "type": "object",
        "properties": {
          "order_id": {"type": "string"},
          "amount": {"type": "number"}
        },
        "required": ["order_id", "amount"],
        "additionalProperties": false
      }
    }
  }
}

应用侧验证 ​

即使模型支持结构化输出,也应在服务端再次执行 Schema 校验,并为拒绝、截断和空响应准备处理分支。

LAYSO AI API 文档