{"record":{"id":"37d5e98ae465716a","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"query-must-be-a-non-empty-string","errorCode":null,"errorMessage":"Query must be a non-empty string","messagePattern":"Query must be a non-empty string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/utils/research_web.py","lineNumber":76,"sourceCode":"    serper_api_key: Optional[str] = Field(None, description=\"API key for Serper\")\n    region: Optional[str] = Field(None, description=\"Country/region code\")\n    language: str = Field(\"en\", description=\"Language code\")\n\n    @validator(\"search_engine\")\n    def validate_search_engine(cls, v):\n        \"\"\"Validate search engine.\"\"\"\n        valid_engines = {\"duckduckgo\", \"bing\", \"searxng\", \"serper\"}\n        if v.lower() not in valid_engines:\n            raise ValueError(\n                f\"Search engine must be one of: {', '.join(valid_engines)}\"\n            )\n        return v.lower()\n\n    @validator(\"query\")\n    def validate_query(cls, v):\n        \"\"\"Validate search query.\"\"\"\n        if not v or not isinstance(v, str):\n            raise ValueError(\"Query must be a non-empty string\")\n        return v\n\n    @validator(\"max_results\")\n    def validate_max_results(cls, v):\n        \"\"\"Validate max results.\"\"\"\n        if v < 1 or v > 100:\n            raise ValueError(\"max_results must be between 1 and 100\")\n        return v\n\n\n# Define advanced PDF detection regex\nPDF_REGEX = re.compile(r\"\\.pdf(#.*)?(\\?.*)?$\", re.IGNORECASE)\n\n\n# Rate limiting decorator\ndef rate_limited(calls: int, period: int = 60):\n    \"\"\"\n    Decorator to limit the rate of function calls.","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/utils/research_web.py#L58-L94","documentation":"ValueError from the pydantic validator on query in research_web: the search query must be a non-empty string. Empty strings, None, or non-string values are rejected before a web search runs.","triggerScenarios":"Passing query='' or query=None (or a non-str) when constructing the search/research parameter model.","commonSituations":"Programmatically generated queries where the template produced an empty string; forwarding user input without checking it.","solutions":["Default the query to a meaningful term when empty","Validate user-supplied query strings before calling search","Strip whitespace and reject blank queries early"],"exampleFix":"# before\nparams = {\"query\": user_input, ...}\n# after\nif not (query := user_input.strip()):\n    raise ValueError(\"query required\")\nparams = {\"query\": query, ...}","handlingStrategy":"validation","validationCode":"if not isinstance(query, str) or not query.strip():\n    raise ValueError(\"query required\")","typeGuard":"def is_valid_query(q) -> bool:\n    return isinstance(q, str) and len(q.strip()) > 0","tryCatchPattern":null,"preventionTips":["Strip and check user queries at the API boundary","Provide non-empty default queries","Reject blank input with your own error before the library does"],"tags":["validation","search","user-input"],"backgroundTag":"empty-argument","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}