S4-16 · 基础S4-16 · Foundation

结构化输出 · 让下游读字段,不猜散文Structured Output · Give Downstream Code Fields, Not Prose to Guess

prose → Schema mold → field validation → unlock downstream action

结构化输出(Structured Output)按固定字段、类型和枚举返回可被代码检查的结果。它是从聊天文字走向系统接口的第一步。Structured output returns fixed fields, types, and enums that code can validate. It is the first step from conversational text toward a system interface.

01 · 表单不靠读心01 · Forms should not require mind reading

快递系统收到“这个很急,尽快处理”后,应该自己猜订单号、优先级和动作吗?A shipping system receives “this is urgent, handle it soon.” Should it guess the order ID, priority, and action?

02把散文拖进 Schema 模具,补齐字段才解锁下游Drag Prose into a Schema Mold and Unlock Downstream Only When Complete

拖动 · 校验 · 解锁drag · validate · unlock
状态 AMetric A
状态 BMetric B
状态 CMetric C

所有概率、得分与输出均为固定种子的教学模拟,不代表真实模型。拖回主变量即可复核结论。All probabilities, scores, and outputs are fixed-seed teaching simulations, not real model output. Move the main variable back to verify the conclusion.

03把刚才的变化拆成 4 个零件Break the Change into Four Parts

Structured Output
FIELD

固定字段Fixed fields

order_id、priority、action 各有明确名字。order_id, priority, and action have explicit names.

TYPE

类型检查Type validation

字符串、数字和枚举不能互相猜。Strings, numbers, and enums cannot be guessed interchangeably.

ALARM

缺字段报警Missing-field alarm

缺一项就明确指出,不让错误静默通过。A missing item is named explicitly instead of failing silently.

GATE

下游门Downstream gate

校验通过前,执行按钮保持锁定。The action button stays locked until validation passes.

04最小机制:主交互能逐项验证Minimal Mechanism: Verify Each Link in the Interaction

MECHANISM
downstream_ready = required_fields_present ∧ types_valid ∧ enums_valid
拖入散文后,模具逐字段检查;三个条件同时成立,下游按钮才从 LOCKED 变 UNLOCKED。After the drop, the mold validates each field. Only all three conditions move downstream from LOCKED to UNLOCKED.
提取字段Extract fields 从散文映射到键map prose to keys
执行校验Validate 缺失 / 类型 / 枚举missing / type / enum
放行下游Release downstream 只接收合法对象accept valid objects only

05故意缺少 action,看下游是否仍敢执行Omit action and See Whether Downstream Still Executes

主动制造失败Create a failure

边界实验Boundary experiment

散文只说“尽快处理”,没有明确退款还是催发货。拖入模具后必须报警,按钮保持锁定。The prose says only “handle it soon,” without specifying refund or expedite. The mold must alarm and keep the button locked.

尚未执行。先在主交互中观察正常机制。Not run yet. Observe the normal mechanism in the main interaction first.
看起来像 JSON 就能直接执行。Anything JSON-shaped can execute directly. → ✓ 必须校验必填字段、类型和枚举。Required fields, types, and enums must be validated.
结构化输出会自动保证事实正确。Structured output guarantees factual values. → ✓ 结构可检查,字段内容仍需业务与事实校验。Structure is checkable; field values still need business and factual validation.
缺字段时让下游自己补。Let downstream fill missing fields. → ✓ 不明确的动作应停在校验门,不应静默猜测。Ambiguous actions should stop at the validation gate, not be guessed silently.
06 · 一句话带走06 · One line to keep

结构化输出把散文变成可校验字段;缺字段就报警,只有完整合法对象才能解锁下游动作。Structured output turns prose into validated fields. Missing data raises an alarm, and only a complete valid object unlocks downstream action.