[PR #994] [MERGED] fix(sdk): return error message instead of raising ValueError for invalid paths #1043

Closed
opened 2026-02-16 09:18:00 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagents/pull/994
Author: @Yo-sure
Created: 2/2/2026
Status: Merged
Merged: 2/2/2026
Merged by: @eyurtsev

Base: masterHead: yo-sure/fix-728-path-validation-error-handling


📝 Commits (4)

  • d870cfb fix(sdk): return error message instead of raising ValueError for invalid paths
  • f9992de Merge branch 'master' into yo-sure/fix-728-path-validation-error-handling
  • 76a5b18 x
  • 4101f37 x

📊 Changes

3 files changed (+382 additions, -8 deletions)

View changed files

📝 libs/deepagents/deepagents/middleware/filesystem.py (+32 -8)
📝 libs/deepagents/tests/unit_tests/test_file_system_tools.py (+170 -0)
libs/deepagents/tests/unit_tests/test_file_system_tools_async.py (+180 -0)

📄 Description

Summary

Handle path validation errors gracefully in filesystem tools by returning error messages as ToolMessages instead of raising ValueError exceptions. This allows the LLM to see the error and retry with a corrected path, rather than crashing the entire agent execution.

Changes

  • Wrap calls in try-except in all 8 tool functions (ls, read_file, write_file, edit_file - both sync and async)
  • Add 4 unit tests covering path traversal, Windows paths, and tilde paths

Test plan

  • All existing tests pass
  • New unit tests pass (test_path_traversal_returns_error_message, test_windows_absolute_path_returns_error_message, test_tilde_path_returns_error_message, test_ls_with_invalid_path_returns_error_message)
  • Manual test with real model (OpenRouter) confirmed error message is returned instead of crash

Closes #728


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagents/pull/994 **Author:** [@Yo-sure](https://github.com/Yo-sure) **Created:** 2/2/2026 **Status:** ✅ Merged **Merged:** 2/2/2026 **Merged by:** [@eyurtsev](https://github.com/eyurtsev) **Base:** `master` ← **Head:** `yo-sure/fix-728-path-validation-error-handling` --- ### 📝 Commits (4) - [`d870cfb`](https://github.com/langchain-ai/deepagents/commit/d870cfba4641252eaf746e9ff3bab705e883ea7b) fix(sdk): return error message instead of raising ValueError for invalid paths - [`f9992de`](https://github.com/langchain-ai/deepagents/commit/f9992de73172ff080f759a8f762f64c42bcd7cdd) Merge branch 'master' into yo-sure/fix-728-path-validation-error-handling - [`76a5b18`](https://github.com/langchain-ai/deepagents/commit/76a5b18d707662ce63bdd38fd03a3d9ad0067bec) x - [`4101f37`](https://github.com/langchain-ai/deepagents/commit/4101f3731e94d4034c1c0d42c22b297c0a178374) x ### 📊 Changes **3 files changed** (+382 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `libs/deepagents/deepagents/middleware/filesystem.py` (+32 -8) 📝 `libs/deepagents/tests/unit_tests/test_file_system_tools.py` (+170 -0) ➕ `libs/deepagents/tests/unit_tests/test_file_system_tools_async.py` (+180 -0) </details> ### 📄 Description ## Summary Handle path validation errors gracefully in filesystem tools by returning error messages as ToolMessages instead of raising ValueError exceptions. This allows the LLM to see the error and retry with a corrected path, rather than crashing the entire agent execution. ## Changes - Wrap calls in try-except in all 8 tool functions (ls, read_file, write_file, edit_file - both sync and async) - Add 4 unit tests covering path traversal, Windows paths, and tilde paths ## Test plan - [x] All existing tests pass - [x] New unit tests pass (`test_path_traversal_returns_error_message`, `test_windows_absolute_path_returns_error_message`, `test_tilde_path_returns_error_message`, `test_ls_with_invalid_path_returns_error_message`) - [x] Manual test with real model (OpenRouter) confirmed error message is returned instead of crash Closes #728 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 09:18:00 -05:00
yindo closed this issue 2026-02-16 09:18:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagents#1043