Preserve extra JSON Schema fields in Anthropic tools

buildTools was only copying "properties" and "required" into
ToolInputSchemaParam, silently dropping root-level constraints
like additionalProperties and $defs. Forward them through the
SDK's ExtraFields map so the full schema reaches the API.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-13 19:36:44 +01:00
parent 1f5e68abe6
commit 91be6dcbfb

View File

@@ -235,10 +235,24 @@ func buildTools(tools []llm.Tool) []anthropic.ToolUnionParam {
reqStrings = append(reqStrings, s)
}
}
tool.InputSchema = anthropic.ToolInputSchemaParam{
extra := make(map[string]any)
for k, v := range schema {
switch k {
case "type", "properties", "required":
default:
extra[k] = v
}
}
inputSchema := anthropic.ToolInputSchemaParam{
Properties: props,
Required: reqStrings,
}
if len(extra) > 0 {
inputSchema.ExtraFields = extra
}
tool.InputSchema = inputSchema
}
}