Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(chat): reject unsupported completion content (#21597)

Sbaaoui Idriss4781a2a8ca23
diff --git a/internal/service/chat_pipeline.go b/internal/service/chat_pipeline.go
index 17a54b33fb..2ea6a57145 100644
--- a/internal/service/chat_pipeline.go
+++ b/internal/service/chat_pipeline.go
@@ -240,6 +240,9 @@ func (s *ChatPipelineService) AsyncChat(
if role, _ := lastMsg["role"].(string); role != "user" {
return nil, fmt.Errorf("the last content of this conversation is not from user")
}
+ if _, err := NormalizeOpenAIMessageContent(lastMsg["content"]); err != nil {
+ return nil, common.NewCodedError(common.CodeArgumentError, err.Error())
+ }
if err := validateChatDatasetAccess(ctx, userID, chat.KBIDs); err != nil {
return nil, err
}
@@ -377,11 +380,11 @@ func (s *ChatPipelineService) AsyncChat(
// === Phase 5: Extract Questions, doc_ids, Attachments ===
common.Info("Phase 5: Extract questions, doc_ids, attachments")
- // Retrieve the last 3 user questions.
+ // Entry validation guarantees the final user content normalizes to a question.
var questions []string
for _, m := range messages {
if role, _ := m["role"].(string); role == "user" {
- if content, ok := m["content"].(string); ok {
+ if content, err := NormalizeOpenAIMessageContent(m["content"]); err == nil {
questions = append(questions, content)
}
}
diff --git a/internal/service/chat_session.go b/internal/service/chat_session.go
index d4472bf7b6..1ee4e79917 100644
--- a/internal/service/chat_session.go
+++ b/internal/service/chat_session.go
@@ -1586,6 +1586,9 @@ func (s *ChatSessionService) normalizeCompletionMessages(
if lastMessage["role"] != "user" {
return nil, "", errors.New("the last content of this conversation is not from user")
}
+ if _, err := NormalizeOpenAIMessageContent(lastMessage["content"]); err != nil {
+ return nil, "", err
+ }
if storeHistoryMessages {
messages = messages[len(messages)-1:]
}