Skip to content

fix: accept array and null content in non-user RAG chat messages - #2556

Merged
Fei-Guo merged 2 commits into
kaito-project:mainfrom
BahaaMattar:fix/rag-chat-message-content-parts
Dec 2, 2026
Merged

Fei-Guo merged 2 commits into
kaito-project:mainfrom
BahaaMattar:fix/rag-chat-message-content-parts

Conversation

@BahaaMattar

Copy link
Copy Markdown
Contributor

Reason for Change:

get_message_content only turns array content into text for user messages. For system, developer and assistant messages it returned the raw list (or None for null content). Two things broke because of that:

  • RAG chat (index_name set) rejected a system/developer/assistant message with array content ([{"type":"text","text":"..."}]) with a 400 and an internal pydantic error. An assistant message with content: null, which the chat validation allows, failed with a 500 when the prompt was built.
  • OutputGuardrails._extract_prompt (used by the non-streaming and streaming guardrails) raised a TypeError joining the list. With fail_open: false the reply became a 500, and with fail_open: true it was returned without being scanned.

Array content is valid OpenAI input for these roles, so the fix joins the text parts for every role (non-text parts such as refusal are skipped) and treats null content as an empty string. The user branch behaves as before and now reuses the same helper.

Requirements

  • added unit tests and e2e tests (if applicable).

Issue Fixed:

Fixes #2555

Notes for Reviewers:

  • New unit tests in tests/test_models.py, plus API tests in test_chat_completions.py for the RAG path (system/developer/assistant arrays, assistant null) and for guardrails with an array system/developer message. The new test cases that cover arrays and null content fail on main (400/500) and pass with the change; the others pin existing behaviour.
  • pytest presets/ragengine/tests: 450 passed, 3 skipped. The one failure (test_default_guardrails_policy_template_has_non_empty_scanners) only fails in my sparse checkout, where charts/ is missing.
  • ruff check and ruff format --check are clean.

get_message_content only unwrapped array content for user messages. A
system, developer or assistant message whose content is an array of text
parts (valid OpenAI input) was returned as a list, which broke two callers:

- the RAG chat path passed the list to ChatMessage, so the request was
  rejected with a 400 carrying an internal pydantic error;
- OutputGuardrails._extract_prompt joined the list into a string and raised
  a TypeError, so with output guardrails enabled the reply was replaced by a
  500 (or, with fail_open, left unscanned).

An assistant message with content null, which the chat validation allows,
was returned as None and made the RAG chat path fail with a 500 when the
prompt was assembled.

Join the text parts of an array for every role, skipping non-text parts, and
treat null content as an empty string.

Fixes kaito-project#2555

Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>

@bfoley13 bfoley13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and adheres to API

@Fei-Guo
Fei-Guo merged commit 0df31b9 into kaito-project:main Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

RAGEngine: system/developer/assistant messages with array content are rejected, and break output guardrails

3 participants