langchain-ai/deepagents · error · ValueError
Path cannot be empty
Error message
Path cannot be empty
What it means
_normalize_path rejects empty or whitespace-only path strings. Since an empty string is ambiguous (root vs. mistake), it raises ValueError('Path cannot be empty') to force callers to be explicit, suggesting '/' for root.
Source
Thrown at libs/deepagents/deepagents/backends/utils.py:751
Args:
path: Path to normalize (None defaults to "/")
Returns:
Normalized path starting with / (without trailing slash unless it's root)
Raises:
ValueError: If path is invalid (empty string after strip)
Example:
_normalize_path(None) -> "/"
_normalize_path("/dir/") -> "/dir"
_normalize_path("dir") -> "/dir"
_normalize_path("/") -> "/"
"""
path = path or "/"
if not path or path.strip() == "":
msg = "Path cannot be empty"
raise ValueError(msg)
normalized = path if path.startswith("/") else "/" + path
# Only root should have trailing slash
if normalized != "/" and normalized.endswith("/"):
normalized = normalized.rstrip("/")
return normalized
def _filter_files_by_path(files: dict[str, Any], normalized_path: str) -> dict[str, Any]:
"""Filter files dict by normalized path, handling exact file matches and directory prefixes.
Expects a normalized path from `_normalize_path` (no trailing slash except root).
Args:
files: Dictionary mapping file paths to file data
normalized_path: Normalized path from `_normalize_path` (e.g., "/", "/dir", "/dir/file")View on GitHub (pinned to a1af029e6e)
Solutions
- Pass '/' explicitly if you mean the root.
- Pass a real directory path instead of an empty string.
- Coalesce blank values before calling: path = path.strip() or '/'.
- Trim and validate agent-supplied paths before invoking glob/grep tools.
Example fix
// before files = glob_search(pattern="*.py", path=" ") // after files = glob_search(pattern="*.py", path=(path or "/").strip() or "/")
Defensive patterns
Strategy: validation
Validate before calling
def normalize_search_path(path: str | None) -> str:
return (path or "/").strip() or "/" Type guard
def is_valid_search_path(path: str | None) -> bool:
return path is None or (isinstance(path, str) and path.strip() != "") Try / catch
try:
results = grep_matches_from_files(pattern, path=user_path)
except ValueError as exc:
if str(exc) == "Path cannot be empty":
results = grep_matches_from_files(pattern, path="/")
else:
raise Prevention
- Coalesce None/empty/blank path values to '/' before calling glob or grep tools.
- Sanitize tool inputs coming from LLM agents (strip whitespace, reject blanks).
- Default the path parameter in your wrappers instead of forwarding raw agent input.
- Add schema-level minimum-length validation for path parameters.
When it happens
Trigger: Calling _normalize_path with a whitespace-only string like ' ' (a None is coalesced to '/', but blank strings are not), typically reached via _glob_search_files or grep_matches_from_files when the path parameter is empty/blank.
Common situations: Glob or grep tool invoked with an empty 'path' parameter by an LLM agent; config values set to '' instead of '/' or a real directory; string manipulation stripping a path to nothing.
Related errors
- Path does not exist: {path}
- user_cwd must be absolute, got {self.user_cwd!r}
- project_root must be absolute, got {self.project_root!r}
- workspace.{field} must be a non-empty absolute path
- workspace.{field} must be an absolute path without traversal
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/53e31ca3fa73596c.
Report an issue: GitHub.