Separate the chunk diagnostics and harden the separator input - #3
Merged
IvoLeist merged 1 commit intoAug 6, 2026
Conversation
…he separator input
Chunk diagnostics:
- Detect a start index that is invalid without being negative. Once the
splitter returns one negative index, the positions it derives from it stay
positive but point at an earlier part of the input, which was reported as if
it were correct. The position is now checked for order and for content.
- Report text that the splitter altered separately from a wrong position.
Splitting between tokens can cut a character that is encoded in several
bytes, which replaces it with the Unicode replacement character. Those chunks
used to be reported as an invalid start index, pointing the user at the wrong
cause.
Custom separator:
- Widen the sanitizer so that characters such as | ; ~ % & $ @ < > " [ ] { }
reach the script instead of being silently replaced by an X, which split the
text at the wrong places.
- Reject a separator that still contains a character Galaxy cannot pass on
unchanged, with a message pointing at the escape syntax.
Other:
- Write the JSON output as UTF-8 as well, instead of the system locale
encoding.
- Let special_token_error() return the error to raise, so the special token
handling has a single contract instead of an unreachable re-raise at both
call sites.
Tests:
- Add a test for a separator that the sanitizer used to mangle.
arash77
force-pushed
the
langchain-text-splitters-round-2
branch
from
August 6, 2026 13:13
dca398d to
6b3338c
Compare
IvoLeist
merged commit Aug 6, 2026
f97dd61
into
IvoLeist:add-langchain_text_splitters
6 checks passed
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.
Follow-up to #2, from a second review round. Two of these produce silently wrong output.
A start index can be wrong without being negative
Once the splitter returns one negative index, the positions it derives from that one stay positive but point at an earlier part of the input, so they looked correct and were written to the JSON as such. Reproducible with a repetitive input, recursive splitter, token length, chunk size 10, overlap 3:
Chunks 6 to 8 claimed the positions of chunks 2 to 4. The position is now checked for order and for content, so all of them are reported as
nulland named in the warning.Chunks that the splitter altered were reported as a wrong position
Splitting between tokens cuts the text at token boundaries, which can fall inside a character that is encoded in several bytes and replaces it with the Unicode replacement character. With the default gpt2 encoding, chunk size 200 and overlap 50, a Chinese input gives 6 corrupted chunks out of 9. Those chunks were reported as an invalid start index, which points the user at a known upstream issue instead of at the corrupted text. They now get their own warning naming the cause and suggesting a character based splitter.
A custom separator was silently replaced by an X
Galaxy's default sanitizer only keeps letters, digits and
-=_.()/+*^,:?!. Anything else, including|and every non-ASCII character, was replaced by a literalX. So a user splitting on|got the text split at every letter X in the document. The sanitizer now keeps| ; ~ % & $ @ < > " [ ] { }, and a validator rejects anything that would still be changed, pointing at the escape syntax. The apostrophe stays rejected on purpose, since the separator is passed inside single quotes.Smaller
special_token_error()returns the error to raise, so the special token handling has one contract instead of an unreachable re-raise at both call sites.planemo lintclean,planemo test21/21.