ScrapeGraphAI/Scrapegraph-ai · error · ValueError
max_results must be between 1 and 100
Error message
max_results must be between 1 and 100
What it means
ValueError from the pydantic validator on max_results in research_web: the number of search results per query must be between 1 and 100 inclusive.
Source
Thrown at scrapegraphai/utils/research_web.py:83
valid_engines = {"duckduckgo", "bing", "searxng", "serper"}
if v.lower() not in valid_engines:
raise ValueError(
f"Search engine must be one of: {', '.join(valid_engines)}"
)
return v.lower()
@validator("query")
def validate_query(cls, v):
"""Validate search query."""
if not v or not isinstance(v, str):
raise ValueError("Query must be a non-empty string")
return v
@validator("max_results")
def validate_max_results(cls, v):
"""Validate max results."""
if v < 1 or v > 100:
raise ValueError("max_results must be between 1 and 100")
return v
# Define advanced PDF detection regex
PDF_REGEX = re.compile(r"\.pdf(#.*)?(\?.*)?$", re.IGNORECASE)
# Rate limiting decorator
def rate_limited(calls: int, period: int = 60):
"""
Decorator to limit the rate of function calls.
Args:
calls (int): Maximum number of calls allowed in the period.
period (int): Time period in seconds.
Returns:
Callable: Decorated function with rate limiting.View on GitHub (pinned to 532dfffbf6)
Solutions
- Clamp max_results to 1..100, e.g. min(100, max(1, n))
- Pick a realistic value like 10-20 per query
- Paginate queries if more coverage is needed
Example fix
# before
params = {"query": q, "max_results": 500}
# after
params = {"query": q, "max_results": min(500, 100)} Defensive patterns
Strategy: validation
Validate before calling
max_results = min(100, max(1, int(max_results)))
Type guard
def is_valid_max_results(n) -> bool:
return isinstance(n, int) and not isinstance(n, bool) and 1 <= n <= 100 Prevention
- Clamp user-supplied result counts to 1..100
- Paginate additional queries instead of huge max_results
- Validate numeric config ranges at load time
When it happens
Trigger: Setting max_results=0, a negative number, or >100 on the web search parameters model.
Common situations: Copying configs from tools that allow unlimited results; setting a very high count to 'get everything' which the backend rejects.
Related errors
- Query must be a non-empty string
- LLM configuration must include an 'api_key'.
- langchain_google_genai is not installed. Please install it u
- The browserbase module is not installed. Please install it u
- undetected_chromedriver is required for ChromiumLoader. Plea
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/2139eaab231e72b5.
Report an issue: GitHub.