From 4286ac963ad68be6c0bba4036ae842ff46ff6a36 Mon Sep 17 00:00:00 2001 From: Alan Date: Thu, 30 Oct 2025 00:21:47 -0500 Subject: [PATCH] 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. --- lua/avante/utils/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/avante/utils/init.lua b/lua/avante/utils/init.lua index db87701..8c00610 100644 --- a/lua/avante/utils/init.lua +++ b/lua/avante/utils/init.lua @@ -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