fix(input): ignore blank lines when reading JSONL files#2423
Open
VectorPeak wants to merge 1 commit into
Open
Conversation
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.
Description
Fix JSONL input loading so blank or whitespace-only lines do not cause the entire
.jsonlfile to be skipped.JSONLinesFileReader.read_file()currently parses every entry returned bytext.splitlines()withjson.loads(line). When a.jsonlfile contains a blank line between otherwise valid records,json.loads("")raisesJSONDecodeError. That exception bubbles up toInputReader._iterate_files(), which logs the error and skips the whole file.This change filters out blank or whitespace-only lines before parsing JSONL records, while preserving the existing behavior for non-empty malformed JSON lines.
Related Issues
Fixes #2424.
Proposed Changes
Checklist
Additional Notes
What Problem This Solves
A JSONL input file may contain accidental blank or whitespace-only lines between otherwise valid records:
{"text":"a"} {"text":"b"}Before this change, the blank line was passed directly to
json.loads(""), which raisesJSONDecodeError. BecauseInputReader._iterate_files()catches exceptions at the file level, the reader skipped the entire file instead of loading the valid records before and after the blank line.Evidence
The affected call chain is:
This PR only ignores blank or whitespace-only JSONL lines. Malformed non-empty lines still go through
json.loads(line)and keep the existing error/skip behavior.Scope
This change only affects JSONL input handling. It does not change CSV, JSON, text, parquet, MarkItDown, storage behavior, or handling of malformed non-empty JSONL records.
Validation
git diff --checkuv run ruff format --check packages/graphrag-input/graphrag_input/jsonl.py tests/unit/indexing/input/test_jsonl_loader.pyuv run ruff check packages/graphrag-input/graphrag_input/jsonl.py tests/unit/indexing/input/test_jsonl_loader.pyuv run --package graphrag-input pytest tests/unit/indexing/input/test_jsonl_loader.py -q- 3 passed