XMem
XMem copied to clipboard
[Bug] Add Missing Payload Range Checks and Empty String Validation in Text Utilities
Context & Problem
In src/utils/text.py and across our text pre-processing hooks, strings are parsed and prepared for memory ingestion. Currently, these helper methods do not strictly validate bounds on inbound string objects.
If an upstream pipeline mistakenly forwards an empty payload "" or an anomalously massive un-chunked string block, the processing utility functions execution loops unnecessarily, wasting resources before passing the payload to downstream validation schemas.
Proposed Solution
Add explicit, lightweight guard clauses at the entry points of our string helper functions to catch edge cases early.
Key Implementation Steps
- Empty Checking: Add an immediate guard clause to return early if
not text.strip()is evaluated. - Length Constraints: Implement a reasonable maximum length threshold verification check to log an explicit warning or throw a descriptive value error early if the string size goes out of normal programmatic boundaries.
- Unit Tests: Add a quick series of unit test assertions inside
tests/unit/test_utils.pycovering null, empty, and boundary conditions to ensure zero regressions.
Impacted Files
src/utils/text.pytests/unit/test_utils.py
@ishaanxgupta
feel free to raise a PR