diff --git a/aaq/tests/helpers.py b/aaq/tests/helpers.py index cde07299..1586aa39 100644 --- a/aaq/tests/helpers.py +++ b/aaq/tests/helpers.py @@ -113,7 +113,10 @@ def post_search_return_empty(self, request): "feedback_secret_key": "secret-key-12345-abcde", "llm_response": None, "query_id": 1, - "search_results": {}, + "search_results": { + "status": 400, + "error": {"detail": "Gibberish text detected: gyugsywgshfsthg"}, + }, "state": "final", } diff --git a/aaq/utils.py b/aaq/utils.py index 017c8ae5..bead7ee1 100644 --- a/aaq/utils.py +++ b/aaq/utils.py @@ -40,14 +40,16 @@ def search(query_text, generate_llm_response, query_metadata): feedback_secret_key = response.json()["feedback_secret_key"] search_results = response.json()["search_results"] - if search_results == {}: - json_msg = { - "message": "Gibberish Detected", - "body": {}, - "feedback_secret_key": feedback_secret_key, - "query_id": query_id, - } - return Response(json_msg, status=status.HTTP_200_OK) + if "error" in search_results: + error_detail = search_results["error"].get("detail", "") + if "Gibberish text detected" in error_detail: + json_msg = { + "message": "Gibberish Detected", + "body": {}, + "feedback_secret_key": feedback_secret_key, + "query_id": query_id, + } + return Response(json_msg, status=status.HTTP_200_OK) json_msg = {} body_content = {}