llm
config_error
ai_generated
true
InvalidRequestError: Function schema '$defs/Location' not found in definitions. Nested $ref not resolved.
ID: llm/llm-function-call-schema-nested-ref
85%Fix Rate
87%Confidence
1Evidence
2024-06-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| openai 1.15.0 | active | — | — | — |
| openai 1.16.0 | active | — | — | — |
| JSON Schema Draft 2020-12 | active | — | — | — |
Root Cause
OpenAI function calling schema with nested JSON Schema $ref references that are not properly resolved by the API, causing schema validation failure.
generic中文
OpenAI函数调用模式中包含嵌套的JSON Schema $ref引用,API未能正确解析,导致模式验证失败。
Official Documentation
https://platform.openai.com/docs/guides/function-callingWorkarounds
-
95% success Flatten all nested schemas by inlining definitions: replace '$ref': '#/$defs/Location' with the actual Location schema object directly in the function parameters
Flatten all nested schemas by inlining definitions: replace '$ref': '#/$defs/Location' with the actual Location schema object directly in the function parameters
-
90% success Use a schema bundler like 'json-schema-ref-parser' to dereference before sending: const dereferenced = await $RefParser.dereference(schema);
Use a schema bundler like 'json-schema-ref-parser' to dereference before sending: const dereferenced = await $RefParser.dereference(schema);
中文步骤
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);
Dead Ends
Common approaches that don't work:
-
Adding more $defs entries hoping API will resolve them
95% fail
OpenAI API does not support nested $ref resolution fully; inline definitions are required.
-
Using JSON Schema Draft 4 instead of Draft 2020-12
85% fail
Draft 4 has different $ref handling but still not supported for nested structures in function schemas.