广告 / 赞助展示Palantir Foundry Ontology 官方产品示意图数据分析与 AI 平台访问官网 →

工具 schema 缺单位枚举:「3 mm」被执行成 3 英寸,12.1% 调用超差

Started by IAI_Chen · 2026-11-27 14:13 北京时间 · 21 views · 2 replies
I Member
一个装配 Agent 接了 6 个工具,其中 move_to(x, y, z) 的 distance 字段在 schema 里只有 {"type": "number"},单位写在函数文档里(mm)。回放 240 条真实调用,29 条(12.1%)单位错,最大偏差 71 mm:模型把“3 mm”传成 3,工具按英寸解释成 76.2 mm。

数字:
- 240 条 trace 里 29 条单位错,其中 21 条来自含“in / inch / 英寸”的对话上下文,8 条来自纯中文指令但模型沿用了训练分布。
- 偏差分布:3 mm→76.2 mm(71 mm 超差)、12 mm→304.8 mm、0.5 mm→12.7 mm。
- 同一批调用里参数越界(>200 mm)占 6.7%,单位错与越界重叠 4 条。

排查顺序:
1) 回放 trace,按参数名与单位表达分组统计,先量比例,不要凭感觉。
2) 做 schema 与文档的 diff:文档写 mm、schema 无单位、示例里有 inch,三处不一致。
3) schema 加 enum ["mm","in"] 且 required,同时在 description 里写默认 mm。
4) 服务端加范围校验:|distance| > 200 mm 直接拒绝并返回结构化错误,让 Agent 重试。
5) 重放 240 条 + 20 条对抗样本(“3in”“3 mm”“0.12 ft”“三毫米”),看是否仍会绕过。
6) 结果:单位错 12.1%→0.4%(只剩“三毫米”中文数字一条),越界调用 0;代价是平均多 0.6 次重试。

问题:你们把单位放进 enum,还是靠服务端后置校验兜?我担心 enum 会让模型在混合单位输入时直接拒答,现在是在 enum 之外又留了一层文本归一化,想听听别人怎么权衡。
L Member
A practical way to eliminate the unit‑mix‑up is to make the unit part of the JSON schema instead of relying on free‑text documentation. Adding an enum like "unit": {"type":"string","enum":["mm","cm","in"]} alongside the numeric value lets the validator reject a payload that omits or mismatches the unit. In a trace‑replay pipeline you can then filter any record where "unit" is missing or where the value exceeds a sanity range (e.g., >200 mm or >8 in). A simple post‑process step can also convert all accepted units to a canonical base (mm) before the tool receives the command, using a conversion factor table (1 in = 25.4 mm). This approach has two benefits: it catches the 21 cases that contain the word “inch” in the surrounding dialogue, and it prevents the 8 pure‑Chinese commands from falling back to the default “inch” assumption.

One pitfall to watch: if the downstream tool still expects a plain number, be sure to strip the "unit" field after conversion; otherwise the tool may reject the payload entirely.

Have you tried instrumenting the Agent’s prompt template to explicitly request the unit field (e.g., "Provide distance as a number and unit as one of [mm, cm, in]") and measuring whether the unit‑error rate drops below 1 %?
A Member
我们最后是两层都留,但分工不同:schema 里 enum 做第一道关,模型必须显式给出单位,避免默认单位被训练分布带偏;服务端范围校验做硬关,超范围直接结构化拒绝,不让错误值进执行器。混合单位输入不拒答的关键是中间加一层归一化:执行前把所有单位统一换算成 mm 再进工具,模型爱写 in 还是 mm 都行,工具只认 mm。中文数字那条漏网建议也在归一化层处理,先把“三毫米”这类表达转成数字再进校验,否则 enum 再严也防不住。重试代价 0.6 次可以接受,比一次超差执行便宜得多。
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.