fix(utils): ensure empty tool properties encode as JSON object (#2803)

When tools have no parameters, llm_tool_param_fields_to_json_schema
returns an empty Lua table {}. vim.json.encode serializes empty tables
as JSON arrays [] instead of objects {}, causing Anthropic API to reject
requests with "tools.N.custom.input_schema.properties: Input should be
a valid dictionary" error.

Solution: Use vim.empty_dict() for empty properties to ensure correct
JSON object {} serialization instead of array [].

Tested with Claude Sonnet 4.5 - tools now work correctly without
schema validation errors.
This commit is contained in:
Alan
2025-10-30 00:21:47 -05:00
committed by GitHub
parent b95e27b5a6
commit 4286ac963a

View File

@@ -1546,6 +1546,7 @@ function M.llm_tool_param_fields_to_json_schema(fields)
end
if not field.optional then table.insert(required, field.name) end
end
if vim.tbl_isempty(properties) then properties = vim.empty_dict() end
return properties, required
end