OpenBMB/ChatDev · error · ValueError
max_results must be positive
Error message
max_results must be positive
What it means
search_in_files validates its max_results parameter up front and rejects non-positive values. Any value <= 0 (0, negative counts, or a value that coerces to <= 0) raises ValueError before any scanning starts. This is a defensive guard so the result cap is always meaningful.
Source
Thrown at functions/function_calling/file.py:732
Optional[Sequence[str]],
ParamMeta(description="Restrict search to these glob patterns"),
] = None,
exclude_globs: Annotated[
Optional[Sequence[str]],
ParamMeta(description="Glob patterns to exclude"),
] = None,
use_regex: Annotated[bool, ParamMeta(description="Treat pattern as regex")]=True,
case_sensitive: Annotated[bool, ParamMeta(description="Match case when True")]=False,
max_results: Annotated[int, ParamMeta(description="Stop after this many matches")]=200,
before_context: Annotated[int, ParamMeta(description="Lines to include before match")]=2,
after_context: Annotated[int, ParamMeta(description="Lines to include after match")]=2,
include_hidden: Annotated[bool, ParamMeta(description="Search hidden files/folders")]=False,
_context: Dict[str, Any] | None = None,
) -> Dict[str, Any]:
"""Search workspace files and return structured matches."""
if max_results <= 0:
raise ValueError("max_results must be positive")
ctx = FileToolContext(_context)
include_patterns = _normalize_globs(globs) or ["**/*"]
exclude_patterns = _normalize_globs(exclude_globs)
matches: List[Dict[str, Any]] = []
searched_files = 0
compiled_regex: Optional[re.Pattern[str]] = None
literal = pattern if case_sensitive else pattern.lower()
if use_regex:
flags = re.MULTILINE
if not case_sensitive:
flags |= re.IGNORECASE
compiled_regex = re.compile(pattern, flags)
for candidate in _iter_candidate_files(
ctx.workspace_root,
include_patterns,View on GitHub (pinned to 4fb2db0ea9)
Solutions
- Pass a positive integer such as 50 or 100 for max_results
- If you intended 'unlimited', pass a large positive cap instead of 0
- Fix upstream computation (page size, config default) so it cannot produce 0
- Add a guard clamping max_results to at least 1 before calling
Example fix
# before search_in_files(pattern="TODO", max_results=0) # after search_in_files(pattern="TODO", max_results=100)
Defensive patterns
Strategy: validation
Validate before calling
max_results = max(1, int(max_results or DEFAULT_CAP)) search_in_files(pattern=p, max_results=max_results)
Type guard
def is_positive_int(v) -> bool:
return isinstance(v, int) and not isinstance(v, bool) and v > 0 Try / catch
try:
search_in_files(pattern=p, max_results=n)
except ValueError as e:
if "max_results" in str(e):
n = 100
search_in_files(pattern=p, max_results=n)
else:
raise Prevention
- Default max_results to a sane positive constant (50/100)
- Clamp user-supplied limits to >= 1 at the boundary
- Treat 0 as 'use default', never pass it through
When it happens
Trigger: Calling search_in_files(..., max_results=0) or a negative number; computing max_results from a configurable page size or subtraction that yields 0; passing a falsy default from an unset config value.
Common situations: Pagination code where limit = page_size * 0 or user-supplied limit defaults to 0; config-driven search where a missing setting is treated as 0; CLI wrappers mapping --max-results=0 as 'unlimited' (not supported here).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- No node types registered; cannot validate workflow
- Unsupported node type '{ntype}' for node '{nid}'. Only {allo
- Design file not found: {config_path}
- YAML root must be a mapping
- expected mapping
AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27).
Data as JSON: /api/errors/fa4be761ce112f3c.
Report an issue: GitHub.