llm
config_error
ai_generated
true
无效请求错误:函数模式中未找到'$defs/Location'定义。嵌套的$ref未解析。
InvalidRequestError: Function schema '$defs/Location' not found in definitions. Nested $ref not resolved.
ID: llm/llm-function-call-schema-nested-ref
85%修复率
87%置信度
1证据数
2024-06-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| openai 1.15.0 | active | — | — | — |
| openai 1.16.0 | active | — | — | — |
| JSON Schema Draft 2020-12 | active | — | — | — |
根因分析
OpenAI函数调用模式中包含嵌套的JSON Schema $ref引用,API未能正确解析,导致模式验证失败。
English
OpenAI function calling schema with nested JSON Schema $ref references that are not properly resolved by the API, causing schema validation failure.
官方文档
https://platform.openai.com/docs/guides/function-calling解决方案
-
Flatten all nested schemas by inlining definitions: replace '$ref': '#/$defs/Location' with the actual Location schema object directly in the function parameters
-
Use a schema bundler like 'json-schema-ref-parser' to dereference before sending: const dereferenced = await $RefParser.dereference(schema);
无效尝试
常见但无效的做法:
-
Adding more $defs entries hoping API will resolve them
95% 失败
OpenAI API does not support nested $ref resolution fully; inline definitions are required.
-
Using JSON Schema Draft 4 instead of Draft 2020-12
85% 失败
Draft 4 has different $ref handling but still not supported for nested structures in function schemas.