{"record":{"id":"e3ffb88abc1ccbe1","repo":"langchain-ai/deepagents","slug":"grep-max-count-must-be-positive-or-none-got-grep","errorCode":null,"errorMessage":"grep_max_count must be positive or None, got {grep_max_count}","messagePattern":"grep_max_count must be positive or None, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/filesystem.py","lineNumber":1703,"sourceCode":"                in any list. Backend capability checks for `execute` and\n                `delete` still apply; listing them when the backend does not\n                support them is a no-op.\n            _permissions: Optional filesystem permission rules enforced directly\n                by this middleware's tool implementations.\n\n                Marked private for now because this is an internal\n                implementation detail and may move to the backend layer in a\n                future change.\n        \"\"\"\n        if isinstance(tools, list) and \"read_file\" not in tools:\n            msg = \"read_file must be included in tools; it is required by FilesystemMiddleware\"\n            raise ValueError(msg)\n        if max_execute_timeout <= 0:\n            msg = f\"max_execute_timeout must be positive, got {max_execute_timeout}\"\n            raise ValueError(msg)\n        if grep_max_count is not None and grep_max_count <= 0:\n            msg = f\"grep_max_count must be positive or None, got {grep_max_count}\"\n            raise ValueError(msg)\n        # Use provided backend or default to StateBackend instance\n        self.backend = backend if backend is not None else StateBackend()\n        if callable(self.backend) and not isinstance(self.backend, BackendProtocol):\n            msg = (\n                \"backend must be an initialized backend instance. Backend factories \"\n                \"were removed in deepagents 0.7; pass StateBackend(), \"\n                \"CompositeBackend(...), or another BackendProtocol instance instead.\"\n            )\n            raise TypeError(msg)\n        self.state_schema = cast(\n            \"type[FilesystemState]\",\n            FilesystemState if _uses_state_backend(self.backend) else AgentState,\n        )\n        if _permissions and supports_execution(self.backend) and not _all_paths_scoped_to_routes(_permissions, self.backend):\n            msg = (\n                \"FilesystemMiddleware does not yet support permissions with backends that \"\n                \"provide command execution (SandboxBackendProtocol). Tool-level permissions \"\n                \"for the execute tool are not implemented. Either remove permissions or use \"","sourceCodeStart":1685,"sourceCodeEnd":1721,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/filesystem.py#L1685-L1721","documentation":"FilesystemMiddleware validates `grep_max_count` in `__init__` and raises ValueError if it is not None and not a positive integer. This cap limits how many grep results can be returned; a non-positive value would make the grep tool useless or produce confusing behavior, so it is rejected eagerly at construction time.","triggerScenarios":"Constructing FilesystemMiddleware(grep_max_count=0) or grep_max_count=-1 (or any value <= 0). Only None (unlimited) or a positive integer is accepted.","commonSituations":"Config-driven setups where the grep cap is read from a settings file or env var defaulting to 0, or code that computes the cap dynamically (e.g. len(results) of an empty list) before passing it in.","solutions":["Pass a positive integer, e.g. FilesystemMiddleware(grep_max_count=50)","Pass None if you want unlimited grep results","Fix the config/env source so the default is a positive value instead of 0"],"exampleFix":"// before\nmw = FilesystemMiddleware(grep_max_count=0)\n// after\nmw = FilesystemMiddleware(grep_max_count=50)  # or None for unlimited","handlingStrategy":"validation","validationCode":"def check_grep_max_count(v):\n    if v is not None and (not isinstance(v, int) or isinstance(v, bool) or v <= 0):\n        raise ValueError(f\"grep_max_count must be positive or None, got {v}\")\n    return v\n# call before constructing FilesystemMiddleware","typeGuard":"def is_positive_int_or_none(v) -> bool:\n    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v > 0)","tryCatchPattern":"try:\n    mw = FilesystemMiddleware(grep_max_count=cfg.grep_max_count)\nexcept ValueError as e:\n    logger.error(\"Invalid middleware config: %s\", e)\n    raise","preventionTips":["Default grep_max_count to a positive value or None in config schemas","Validate config ints at load time, not at middleware construction","Watch for 0 coming from falsy-default patterns like `os.environ.get(\"X\", 0)`"],"tags":["python","validation","filesystem","config"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}