From df43afc89bfd049a7142281a90afa8a471bf2607 Mon Sep 17 00:00:00 2001 From: yangdx Date: Mon, 29 Sep 2025 13:10:15 +0800 Subject: [PATCH] Relax conversation history role validation requirements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Remove strict role value checking • Allow any non-empty string roles --- lightrag/api/routers/query_routes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lightrag/api/routers/query_routes.py b/lightrag/api/routers/query_routes.py index f4fb30a6..53cc41c0 100644 --- a/lightrag/api/routers/query_routes.py +++ b/lightrag/api/routers/query_routes.py @@ -111,10 +111,10 @@ class QueryRequest(BaseModel): if conversation_history is None: return None for msg in conversation_history: - if "role" not in msg or msg["role"] not in {"user", "assistant"}: - raise ValueError( - "Each message must have a 'role' key with value 'user' or 'assistant'." - ) + if "role" not in msg: + raise ValueError("Each message must have a 'role' key.") + if not isinstance(msg["role"], str) or not msg["role"].strip(): + raise ValueError("Each message 'role' must be a non-empty string.") return conversation_history def to_query_params(self, is_stream: bool) -> "QueryParam":