Skip to content

fix(ai-prompt-decorator): keep empty JSON arrays when rewriting the body - #14984

Open
BetterAndBetterII wants to merge 1 commit into
Kong:masterfrom
BetterAndBetterII:fix/ai-prompt-decorator-empty-array
Open

fix(ai-prompt-decorator): keep empty JSON arrays when rewriting the body#14984
BetterAndBetterII wants to merge 1 commit into
Kong:masterfrom
BetterAndBetterII:fix/ai-prompt-decorator-empty-array

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Summary

ai-prompt-decorator re-serialized the request through the immutable body proxy. cycle_aware_deep_copy of that proxy keeps no own keys, so cjson wrote {} and empty JSON arrays such as tools: [] or nested required: [] became objects. Upstream Anthropic then rejects the request with 400 tools: Input should be a valid array.

Copy the underlying table (so array_mt survives), encode with kong.tools.cjson, and write the raw body.

Fixes #14983

Test plan

  • Unit: decorate an immutable body whose tools and nested required are empty JSON arrays; encoded output keeps []
  • Existing prepend/append message-order unit cases still pass

Copy the real request table out of the immutable proxy before decorate,
and encode with kong.tools.cjson so tools: [] / required: [] stay arrays.
@CLAassistant

CLAassistant commented Aug 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@BetterAndBetterII

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai-prompt-decorator re-encodes empty JSON arrays as objects (tools: [] → tools: {})

2 participants