# 无效请求错误：函数模式中未找到'$defs/Location'定义。嵌套的$ref未解析。

- **ID:** `llm/llm-function-call-schema-nested-ref`
- **领域:** llm
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

OpenAI函数调用模式中包含嵌套的JSON Schema $ref引用，API未能正确解析，导致模式验证失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| openai 1.15.0 | active | — | — |
| openai 1.16.0 | active | — | — |
| JSON Schema Draft 2020-12 | active | — | — |

## 解决方案

1. ```
   Flatten all nested schemas by inlining definitions: replace '$ref': '#/$defs/Location' with the actual Location schema object directly in the function parameters
   ```
2. ```
   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** — OpenAI API does not support nested $ref resolution fully; inline definitions are required. (95% 失败率)
- **Using JSON Schema Draft 4 instead of Draft 2020-12** — Draft 4 has different $ref handling but still not supported for nested structures in function schemas. (85% 失败率)
