{"record":{"id":"3a1f75112a713180","repo":"microsoft/graphrag","slug":"drift-search-query-cannot-be-empty","errorCode":null,"errorMessage":"DRIFT Search query cannot be empty.","messagePattern":"DRIFT Search query cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/graphrag/graphrag/query/structured_search/drift_search/search.py","lineNumber":213,"sourceCode":"        \"\"\"\n        Perform an asynchronous DRIFT search.\n\n        Args:\n            query (str): The query to search for.\n            conversation_history (Any, optional): The conversation history, if any.\n            reduce (bool, optional): Whether to reduce the response to a single comprehensive response.\n\n        Returns\n        -------\n        SearchResult: The search result containing the response and context data.\n\n        Raises\n        ------\n        ValueError: If the query is empty.\n        \"\"\"\n        if query == \"\":\n            error_msg = \"DRIFT Search query cannot be empty.\"\n            raise ValueError(error_msg)\n\n        llm_calls, prompt_tokens, output_tokens = {}, {}, {}\n\n        start_time = time.perf_counter()\n\n        # Check if query state is empty\n        if not self.query_state.graph:\n            # Prime the search with the primer\n            primer_context, token_ct = await self.context_builder.build_context(query)\n            llm_calls[\"build_context\"] = token_ct[\"llm_calls\"]\n            prompt_tokens[\"build_context\"] = token_ct[\"prompt_tokens\"]\n            output_tokens[\"build_context\"] = token_ct[\"output_tokens\"]\n\n            primer_response = await self.primer.search(\n                query=query, top_k_reports=primer_context\n            )\n            llm_calls[\"primer\"] = primer_response.llm_calls\n            prompt_tokens[\"primer\"] = primer_response.prompt_tokens","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/microsoft/graphrag/blob/f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704/packages/graphrag/graphrag/query/structured_search/drift_search/search.py#L195-L231","documentation":"DriftSearch.search validates up front that the query string is non-empty (query == \"\") and raises this ValueError otherwise. It is a simple input guard so the search pipeline never runs on an empty prompt.","triggerScenarios":"Calling DriftSearch.search(''), DriftSearch.stream_search(''), or _search_step with an empty string, e.g. because a variable holding the user question was never set or was stripped to ''.","commonSituations":"Programmatic query loops where some rows of an input file have blank questions, frontends forwarding an empty input box, or whitespace-only strings that were stripped before the call.","solutions":["Validate the query is a non-empty, non-whitespace string before calling search","Default to a meaningful placeholder or skip empty inputs in batch processing","Strip and check the string: if not query.strip(): raise/skip in your own code first"],"exampleFix":"# before\nresult = await drift_search.aresolve(user_query)  # user_query may be ''\n\n# after\nif not user_query or not user_query.strip():\n    raise ValueError('Query is required')\nresult = await drift_search.aresolve(user_query)","handlingStrategy":"validation","validationCode":"if not query or not query.strip():\n    raise ValueError(\"Query must be a non-empty string\")\nresult = await drift_search.aresolve(query)","typeGuard":"def is_valid_query(q) -> bool:\n    return isinstance(q, str) and len(q.strip()) > 0","tryCatchPattern":null,"preventionTips":["Sanitize user input upstream (strip and reject blank strings)","In batch pipelines, filter out empty rows before invoking search"],"tags":["graphrag","drift-search","input-validation","empty-query"],"backgroundTag":"empty-input-validation","analyzedSha":"f40e9a26ce62ba0b3fef8837d24aafdcc6e6c704","analyzedAt":"2026-08-27T11:16:29.677Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}