calesthio/OpenMontage · error · FileNotFoundError

Input file not found

Error message

Input file not found: {path}

What it means

FileNotFoundError from the Grok image tool's _file_to_data_uri helper. Before calling the x.ai images API in edit mode, a local image_path argument is read, base64-encoded, and wrapped as a data: URI; if the path does not exist on disk the helper raises before any network call happens.

Solutions

  1. Verify the file exists before invoking the tool (Path(p).exists())
  2. Use an absolute path, or resolve relative paths against a known base directory
  3. Expand '~' explicitly: str(Path(p).expanduser().resolve())
  4. If the file should have been produced by an earlier pipeline step, check that step's output before retrying

Example fix

// before
inputs = {"mode": "edit", "image_path": "~/pictures/cat.png"}
// after
from pathlib import Path
p = Path("~/pictures/cat.png").expanduser().resolve()
assert p.is_file(), f"missing input: {p}"
inputs = {"mode": "edit", "image_path": str(p)}
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

def valid_image_path(p: str) -> bool:
    path = Path(p).expanduser().resolve()
    return path.is_file() and path.suffix.lower() in {".png", ".jpg", ".jpeg", ".webp"}

assert valid_image_path(inputs["image_path"]) or "image_url" in inputs

Try / catch

try:
        result = grok_image_tool.run(inputs)
    except FileNotFoundError as e:
        # path missing; resolve or regenerate the input before retry

Prevention

When it happens

Trigger: Calling grok_image with image_path (or a member of image_paths) pointing to a non-existent file: typo in the path, relative path resolved against the wrong working directory, file deleted between planning and execution, or a sandboxed agent passing a path outside its workspace.

Common situations: Relative paths like 'assets/input.png' run from a different cwd; agent-generated paths from a prior step that never materialized; unexpanded '~' in the path (the helper uses plain Path(path_str) without expanduser).

Related errors


AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15). Data as JSON: /api/errors/0d258366fc748768. Report an issue: GitHub.

Appendix: source

Thrown at tools/graphics/grok_image.py:30

from tools.base_tool import (
    BaseTool,
    Determinism,
    ExecutionMode,
    ResourceProfile,
    RetryPolicy,
    ToolResult,
    ToolRuntime,
    ToolStability,
    ToolStatus,
    ToolTier,
)


def _file_to_data_uri(path_str: str) -> str:
    path = Path(path_str)
    if not path.exists():
        raise FileNotFoundError(f"Input file not found: {path}")
    mime_type, _ = mimetypes.guess_type(path.name)
    if not mime_type:
        mime_type = "application/octet-stream"
    encoded = base64.b64encode(path.read_bytes()).decode("ascii")
    return f"data:{mime_type};base64,{encoded}"


def _normalize_image_input(url_value: str | None, path_value: str | None) -> dict[str, str] | None:
    if url_value:
        return {"url": url_value, "type": "image_url"}
    if path_value:
        return {"url": _file_to_data_uri(path_value), "type": "image_url"}
    return None


class GrokImage(BaseTool):
    name = "grok_image"
    version = "0.1.0"

View on GitHub (pinned to 95e1c3d0ab)