invoke-ai/InvokeAI · warning

Empty path segments not allowed in subfolder path

Error message

Empty path segments not allowed in subfolder path

What it means

Empty segments in the subfolder (e.g. 'a//b', 'a/', or leading '/') are rejected to keep paths canonical and avoid ambiguity in storage layout. Raises ValueError('Empty path segments not allowed in subfolder path').

Source

Thrown at invokeai/app/services/image_files/image_files_disk.py:291

            raise ValueError("Image path outside outputs folder, potential directory traversal detected")

        return resolved_image_path

    @staticmethod
    def _validate_subfolder(subfolder: str) -> None:
        """Validates a subfolder path to prevent directory traversal while allowing controlled subdirectories."""
        if not subfolder:
            return
        if "\\" in subfolder:
            raise ValueError("Backslashes not allowed in subfolder path")
        if subfolder.startswith("/"):
            raise ValueError("Absolute paths not allowed in subfolder path")
        parts = subfolder.split("/")
        for part in parts:
            if part == "..":
                raise ValueError("Parent directory references not allowed in subfolder path")
            if part == "":
                raise ValueError("Empty path segments not allowed in subfolder path")

    def validate_path(self, path: Union[str, Path]) -> bool:
        """Validates the path given for an image or thumbnail."""
        path = path if isinstance(path, Path) else Path(path)
        return path.exists()

    def get_workflow(self, image_name: str, image_subfolder: str = "") -> str | None:
        image = self.get(image_name, image_subfolder=image_subfolder)
        workflow = image.info.get("invokeai_workflow", None)
        if isinstance(workflow, str):
            return workflow
        return None

    def get_graph(self, image_name: str, image_subfolder: str = "") -> str | None:
        image = self.get(image_name, image_subfolder=image_subfolder)
        graph = image.info.get("invokeai_graph", None)
        if isinstance(graph, str):
            return graph

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Normalize the subfolder with posixpath.normpath before calling
  2. Filter out empty parts: '/'.join(p for p in sub.split('/') if p)
  3. Reject or strip trailing/leading slashes at your API boundary

Example fix

// before
sub = board + '/'  # 'myboard/'
// after
sub = '/'.join(p for p in sub.split('/') if p)
Defensive patterns

Strategy: validation

Validate before calling

import posixpath
def canonical_subfolder(s: str) -> str:
    return posixpath.normpath(s.strip('/'))
sub = canonical_subfolder(sub)
assert '' not in sub.split('/')

Type guard

def has_no_empty_segments(s: object) -> bool:
    return isinstance(s, str) and s != '' and all(p for p in s.split('/'))

Try / catch

try:
    service.get(name, image_subfolder=subfolder)
except ValueError as e:
    if 'Empty path segments' in str(e):
        subfolder = '/'.join(p for p in subfolder.split('/') if p)
        service.get(name, image_subfolder=subfolder)

Prevention

When it happens

Trigger: Passing image_subfolder like 'a//b', 'a/', or '' handled after the falsy check (non-empty but with empty segments); joining strings with trailing separators.

Common situations: String-concatenating subfolder parts with stray slashes; splitting/rejoining paths from user input; trailing slash from URL parsing.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/b20fadb4c9e7562e. Report an issue: GitHub.