nic-6443 opened a new pull request, #13634:
URL: https://github.com/apache/apisix/pull/13634

   ### Description
   
   `ai-prompt-guard` returns 500 when any inspected chat message has structured 
`content`.
   
   OpenAI Chat Completions allows `messages[].content` to be either a plain 
string or an array of typed parts, e.g.:
   
   ```json
   { "role": "user", "content": [ { "type": "text", "text": "hello" } ] }
   ```
   
   The plugin collected `msg.content` as-is and then called `table.concat`, so 
an array element triggers:
   
   ```
   ai-prompt-guard.lua: invalid value (table) at index N in table for 'concat'
   ```
   
   and the request fails with a Lua runtime error. This is easy to hit with 
`match_all_conversation_history` / `match_all_roles` enabled, since real 
clients often send structured assistant/history messages.
   
   The fix flattens each message's content before concatenation — strings pass 
through, and the text parts of an array are extracted — mirroring how the 
protocol adapters (`openai-chat`, `anthropic-messages`, etc.) already pull text 
out of `content`. Non-text parts (e.g. `image_url`) are ignored, so there is 
nothing to concat that isn't a string.
   
   #### Which issue(s) this PR fixes:
   
   Fixes #
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [x] I have verified that this change is backward compatible
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to