hermes - 💡(How to fix) Fix Bug: read_file produces confusing error when called with empty/missing path

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  • Agent log: 2026-05-24 19:01:55,445 WARNING … Tool read_file returned error (0.08s): … "File not found: "
  • DeepSeek V4 Pro produced this 3 times in one session (likely a hallucination under context pressure)
  • The confusing output wasted 3 API calls as the model could not self-correct

Root Cause

_handle_read_file at tools/file_tools.py uses args.get("path", "") as a default. Unlike _handle_write_file (which already validates path at line 1196), _handle_read_file has no guard for empty/missing paths.

Fix Action

Fix

Two changes to tools/file_tools.py:

1. Add path validation to _handle_read_file (matching _handle_write_file's existing pattern):

def _handle_read_file(args, **kw):
    tid = kw.get("task_id") or "default"
    if not args.get("path") or not isinstance(args.get("path"), str):
        return tool_error(
            "read_file: missing required field 'path'. Re-emit the tool call with "
            "a valid file path (absolute, relative, or ~/path)."
        )
    return read_file_tool(path=args["path"], offset=args.get("offset", 1), limit=args.get("limit", 500), task_id=tid)

2. Add minLength: 1 to the schema for a stronger API-level signal:

"path": {"type": "string", "minLength": 1, "description": "Path to the file to read …"}

Code Example

"File not found: ", "similar_files": ["./backups", "./fix_sql.py", "./fix_views.py"]

---

def _handle_read_file(args, **kw):
    tid = kw.get("task_id") or "default"
    if not args.get("path") or not isinstance(args.get("path"), str):
        return tool_error(
            "read_file: missing required field 'path'. Re-emit the tool call with "
            "a valid file path (absolute, relative, or ~/path)."
        )
    return read_file_tool(path=args["path"], offset=args.get("offset", 1), limit=args.get("limit", 500), task_id=tid)

---

"path": {"type": "string", "minLength": 1, "description": "Path to the file to read …"}
RAW_BUFFERClick to expand / collapse

Bug description

When the model calls read_file without a path argument (or with an empty string), the tool handler defaults to "" and the empty path propagates through the entire read pipeline to _suggest_similar_files, producing the confusing error:

"File not found: ", "similar_files": ["./backups", "./fix_sql.py", "./fix_views.py"]

The empty string resolves to the CWD, so the similar files are just random files in the working directory — not helpful and wastes API calls as the model tries to interpret the non-sequitur.

Root cause

_handle_read_file at tools/file_tools.py uses args.get("path", "") as a default. Unlike _handle_write_file (which already validates path at line 1196), _handle_read_file has no guard for empty/missing paths.

Observed behavior

  • Agent log: 2026-05-24 19:01:55,445 WARNING … Tool read_file returned error (0.08s): … "File not found: "
  • DeepSeek V4 Pro produced this 3 times in one session (likely a hallucination under context pressure)
  • The confusing output wasted 3 API calls as the model could not self-correct

Fix

Two changes to tools/file_tools.py:

1. Add path validation to _handle_read_file (matching _handle_write_file's existing pattern):

def _handle_read_file(args, **kw):
    tid = kw.get("task_id") or "default"
    if not args.get("path") or not isinstance(args.get("path"), str):
        return tool_error(
            "read_file: missing required field 'path'. Re-emit the tool call with "
            "a valid file path (absolute, relative, or ~/path)."
        )
    return read_file_tool(path=args["path"], offset=args.get("offset", 1), limit=args.get("limit", 500), task_id=tid)

2. Add minLength: 1 to the schema for a stronger API-level signal:

"path": {"type": "string", "minLength": 1, "description": "Path to the file to read …"}

Related

  • Issue #522 (Tool Argument Validation) — broader feature request, does not cover this targeted fix

Labels

type/bug

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix Bug: read_file produces confusing error when called with empty/missing path