From a13a0594b8ef38fbab2c4812d9f3ce3f0b1fa219 Mon Sep 17 00:00:00 2001 From: Aditya Vaish Date: Wed, 8 Oct 2025 01:07:32 +0530 Subject: [PATCH] fix trim mode values before validating --- surfsense_backend/app/utils/validators.py | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/surfsense_backend/app/utils/validators.py b/surfsense_backend/app/utils/validators.py index fbbe260b4..2a2b480a7 100644 --- a/surfsense_backend/app/utils/validators.py +++ b/surfsense_backend/app/utils/validators.py @@ -222,15 +222,20 @@ def validate_research_mode(research_mode: Any) -> str: status_code=400, detail="research_mode must be a string" ) - + normalized_mode = research_mode.strip().upper() + if not normalized_mode: + raise HTTPException( + status_code=400, + detail="research_mode cannot be empty" + ) + valid_modes = ["GENERAL", "DEEP", "DEEPER", "QNA"] - if research_mode.upper() not in valid_modes: + if normalized_mode not in valid_modes: raise HTTPException( status_code=400, detail=f"research_mode must be one of: {', '.join(valid_modes)}" ) - - return research_mode.upper() + return normalized_mode def validate_search_mode(search_mode: Any) -> str: @@ -254,15 +259,20 @@ def validate_search_mode(search_mode: Any) -> str: status_code=400, detail="search_mode must be a string" ) - + normalized_mode = search_mode.strip().upper() + if not normalized_mode: + raise HTTPException( + status_code=400, + detail="search_mode cannot be empty" + ) + valid_modes = ["CHUNKS", "DOCUMENTS"] - if search_mode.upper() not in valid_modes: + if normalized_mode not in valid_modes: raise HTTPException( status_code=400, detail=f"search_mode must be one of: {', '.join(valid_modes)}" ) - - return search_mode.upper() + return normalized_mode def validate_messages(messages: Any) -> list[dict]: