Repository navigation
Conversation
An OpenAI-format chat request with `tools: []` routed to the
anthropic provider was sent upstream as `tools: {}`. `to_tools()`
builds a fresh Lua table without `array_mt`, so cjson encodes the
empty result as an object and Anthropic rejects the request with
`400 tools: Input should be a valid array`.
* create the translated tools table with `cjson.array_mt`
* add a unit test that encodes the translated request
Related Kong#14983
Assisted-by: Claude Code/claude-opus-5
Machine: A-Mac16-2019-PaloAlto
Account: tonydzi
Operator: anton
Co-Authored-By: Claude Opus 5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An OpenAI-format chat request with
tools: [], proxied byai-proxyto theanthropicprovider, leaves Kong as"tools": {}. Anthropic rejects that with400 tools: Input should be a valid array— the same error reported in #14983.Root cause:
to_tools()inkong/llm/drivers/anthropic.luabuilds the translated list as a plain{}. The request body itself is decoded witharray_mt(kong.request.get_body→decode_with_array_mt), but this new table has no metatable, so when nothing is insertedcjsonencodes it as an object innormalize-request→kong.service.request.set_body.The fix creates that table with
cjson.array_mt. Non-empty tools encode exactly as before.This does not replace #14984. #14983 is about
ai-prompt-decoratorwith the native Anthropic format, which is not in this repo's decorator schema (openai,bedrock,gemini). I found this separate path on master while reproducing it: no decorator needed, justai-proxy+anthropic+tools: [].Reproduction
restyin thekong:3.9image with this repo's master sources mounted onpackage.path. Input decoded withkong.tools.cjson.decode_with_array_mt, thenanthropic.to_format(..., "llm/v1/chat"), thencjson.safe.encode(whatset_bodyuses):Tests
New unit case in
spec/03-plugins/38-ai-proxy/01-unit_spec.lua("anthropic tools").Run locally: busted 2.3.0 under
restyin thekong:3.9image (OpenResty LuaJIT + lua-cjson from that image), master sources from this branch. This is not Kong'smake testdev environment.not ok—Passed in: '{..."tools":{}}',Expected: '"tools":[]'ok01-unit_spec.lua: 156/156 ok with the change, 155/156 without (only the new case fails)luacheckon both touched Lua files: 0 warnings / 0 errorsNot run: integration specs (
03-anthropic_integration_spec.lua) and the full CI matrix.Changelog:
changelog/unreleased/kong/fix-ai-proxy-anthropic-empty-tools.yml.I built this with Claude Code as an implementation collaborator; I checked the reproduction and test runs above.
— Anton Dziatkovskii · github.com/tonydzi
🤖 Generated with Claude Code