Skip to content

fix: return text message for empty search results in file_read#488

Open
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix-empty-search-results
Open

fix: return text message for empty search results in file_read#488
xlyoung wants to merge 1 commit into
strands-agents:mainfrom
xlyoung:fix-empty-search-results

Conversation

@xlyoung
Copy link
Copy Markdown

@xlyoung xlyoung commented Jun 4, 2026

Summary

Fixes #303

When file_read in search mode finds no matching results, it previously returned an empty content list {"content": []}, which caused downstream Bedrock API errors.

Changes

  • src/strands_tools/file_read.py: Added a check for empty search results in the search mode code path. When no results are found, it now returns a helpful text message (No search results found for pattern '<pattern>' in <file_path>) instead of an empty content list, while maintaining status: "success".
  • tests/test_file_read.py: Added test_file_read_tool_direct_search_no_results test to verify the fix.

Testing

All 19 existing tests pass, including the new test:

tests/test_file_read.py::test_file_read_tool_direct_search_no_results PASSED

Before

{"toolUseId": "...", "status": "success", "content": []}

After

{"toolUseId": "...", "status": "success", "content": [{"text": "No search results found for pattern 'xyz' in /path/to/file.txt"}]}

Fixes strands-agents#303

When file_read in search mode found no matching results, it returned
an empty content list [] which caused downstream Bedrock API errors.
Now it returns a helpful text message indicating no search results were
found, while maintaining status: 'success'.
@xlyoung xlyoung requested a deployment to manual-approval June 4, 2026 02:32 — with GitHub Actions Waiting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] file_read search mode returns empty list if results is empty

1 participant