Fix filename length error when using LLM-generated prompts #272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Filename length error when using LLM-generated prompts
Fixes #266
Problem
When LLM-generated text prompts are used directly as filenames, errors occur when the prompt exceeds filesystem filename length limits (typically 255 characters). This issue manifests around line 256 of
agent_core.pywhencall_sam_service()creates files using the prompt as the filename.Example Error Case
A prompt like:
Results in a filename that is 191+ characters long, which can cause filesystem errors when combined with path components and file extensions.
Solution
Created a
sanitize_filename()helper function that:Changes
sam3/agent/helpers/filename_utils.py- Helper function for filename sanitizationsam3/agent/client_sam3.py- Uses sanitized filenames when creating output filessam3/agent/agent_core.py- Uses sanitized filenames in multiple places (lines 324, 398)sam3/agent/inference.py- Uses sanitized filenames for batch inferenceReproduction
Before Fix
When a long LLM-generated prompt like:
(191 characters) is used directly as a filename, it causes errors:
After Fix
The same prompt is sanitized and truncated:
Testing
Code Quality