Fix filename length error when using LLM-generated prompts#272
Open
mattiagaggi wants to merge 2 commits intofacebookresearch:mainfrom
Open
Fix filename length error when using LLM-generated prompts#272mattiagaggi wants to merge 2 commits intofacebookresearch:mainfrom
mattiagaggi wants to merge 2 commits intofacebookresearch:mainfrom
Conversation
- Add sanitize_filename() helper to truncate and sanitize filenames - Update client_sam3.py to use sanitized filenames - Update agent_core.py to use sanitized filenames (fixes issue around line 256) - Update inference.py to use sanitized filenames Fixes issue where long LLM-generated prompts used as filenames exceed filesystem limits and cause errors.
Clean up the convoluted filename length calculation logic to be more straightforward and maintainable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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