Repository navigation
fix: accept array and null content in non-user RAG chat messages - #2556
Merged
Fei-Guo merged 2 commits intoDec 2, 2026
Merged
Conversation
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
approved these changes
Nov 20, 2026
bfoley13
left a comment
Collaborator
There was a problem hiding this comment.
Looks good and adheres to API
BahaaMattar
temporarily deployed
to
unit-tests
November 20, 2026 14:54 — with
GitHub Actions
Inactive
BahaaMattar
requested a deployment
to
e2e-test
November 20, 2026 14:54 — with
GitHub Actions
Waiting
BahaaMattar
temporarily deployed
to
unit-tests
November 20, 2026 14:54 — with
GitHub Actions
Inactive
BahaaMattar
requested a deployment
to
e2e-test
November 20, 2026 14:54 — with
GitHub Actions
Waiting
BahaaMattar
requested a deployment
to
e2e-test
November 20, 2026 14:54 — with
GitHub Actions
Waiting
BahaaMattar
requested a deployment
to
e2e-test
November 20, 2026 14:54 — with
GitHub Actions
Waiting
BahaaMattar
requested a deployment
to
e2e-test
November 20, 2026 14:54 — with
GitHub Actions
Waiting
BahaaMattar
requested a deployment
to
e2e-test
November 20, 2026 14:54 — with
GitHub Actions
Waiting
BahaaMattar
requested a deployment
to
e2e-test
November 20, 2026 14:54 — with
GitHub Actions
Waiting
Fei-Guo
approved these changes
Dec 2, 2026
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.
Reason for Change:
get_message_contentonly turns array content into text for user messages. For system, developer and assistant messages it returned the raw list (orNonefor null content). Two things broke because of that:index_nameset) rejected a system/developer/assistant message with array content ([{"type":"text","text":"..."}]) with a 400 and an internal pydantic error. An assistant message withcontent: 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 aTypeErrorjoining the list. Withfail_open: falsethe reply became a 500, and withfail_open: trueit 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
refusalare skipped) and treats null content as an empty string. The user branch behaves as before and now reuses the same helper.Requirements
Issue Fixed:
Fixes #2555
Notes for Reviewers:
tests/test_models.py, plus API tests intest_chat_completions.pyfor 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, wherecharts/is missing.ruff checkandruff format --checkare clean.