Skip to content

fix(ai-prompt-template): fix malformed JSON error message#13096

Merged
Baoyuantop merged 3 commits into
apache:masterfrom
sihyeonn:fix/ai-prompt-template-error-msg
Apr 16, 2026
Merged

fix(ai-prompt-template): fix malformed JSON error message#13096
Baoyuantop merged 3 commits into
apache:masterfrom
sihyeonn:fix/ai-prompt-template-error-msg

Conversation

@sihyeonn

Copy link
Copy Markdown
Contributor

Description

The error message in get_request_body_table() had two issues:

  1. Grammatical error: "could not get parse" instead of "could not parse"
  2. String concatenation bug: err was added as a separate table element ({ message = "...: ", err }) instead of being concatenated to the message string ({ message = "...: " .. err }), causing the error detail to be silently dropped from the response.

The correct pattern already exists in ai-prompt-decorator.lua:76.

Before

return nil, { message = "could not get parse JSON request body: ", err }

After

return nil, { message = "could not parse JSON request body: " .. err }

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Mar 18, 2026
@Baoyuantop

Copy link
Copy Markdown
Contributor

Please update the code in all relevant places.

@Baoyuantop

Copy link
Copy Markdown
Contributor

Hi @sihyeonn, following up on the previous review comments. Please let us know if you have any updates. Thank you.

@sihyeonn

Copy link
Copy Markdown
Contributor Author

Hi, thanks for the follow-up. The fix has been applied — the error message now correctly reflects the malformed JSON case. Ready for review whenever you get a chance.

@Baoyuantop

Copy link
Copy Markdown
Contributor

Hi @sihyeonn, I mean, there are several similar errors; could you fix them all at once?

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 8, 2026
The error message in get_request_body_table() had two issues:
- Grammatical error: "could not get parse" instead of "could not parse"
- The err variable was added as a separate table element instead of
  being concatenated to the message string, causing the error detail
  to be silently dropped.

This aligns with the correct pattern used in ai-prompt-decorator.lua.

Signed-off-by: Sihyeon Jang <[email protected]>
…ted places

Apply the same error message fix to ai-prompt-decorator.lua and
core/request.lua, which contained the same "could not get parse"
typo as ai-prompt-template.lua.

Signed-off-by: Sihyeon Jang <[email protected]>
Update expected response_body in ai-proxy.t and ai-proxy-multi.t to
match the corrected error message "could not parse JSON request body"
(removed erroneous "get" from "could not get parse").

Signed-off-by: Sihyeon Jang <[email protected]>
@sihyeonn
sihyeonn force-pushed the fix/ai-prompt-template-error-msg branch from c64875a to f05ec83 Compare April 9, 2026 23:08
@Baoyuantop
Baoyuantop merged commit 301670a into apache:master Apr 16, 2026
19 checks passed
@sihyeonn
sihyeonn deleted the fix/ai-prompt-template-error-msg branch April 16, 2026 22:49
wistefan pushed a commit to wistefan/apisix that referenced this pull request Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants