Repository navigation
Fix tag CSV parser ignoring the documented TAB delimiter - #17496
Conversation
rag/app/tag.py documents TAB as the delimiter separating content from tags, but the .csv branch calls csv.reader without a delimiter argument, so it always splits on commas. A TAB-delimited file whose content field contains a comma splits into three fields, fails the len(row) == 2 check and is silently dropped. If only the tag field contains a comma the line splits into two fields by coincidence, leaving the tab and the first tag inside the content and dropping that tag. Detect the delimiter the same way rag/app/qa.py already does for its own .csv branch. Plain comma-delimited files are unaffected.
📝 WalkthroughWalkthroughCSV parsing now detects tab-separated versus comma-separated input before constructing ChangesCSV Parsing
Estimated code review effort: 1 (Trivial) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/app/tag.py`:
- Around line 95-100: Add a module-level logger and log the delimiter selected
by the parser immediately after the delimiter assignment in the CSV parsing
flow. Include only the selected delimiter in the debug or info message, and do
not log input lines or file contents.
- Around line 95-100: Update delimiter detection in the CSV parsing flow around
csv.reader so it does not inspect raw tab characters before quote parsing;
determine whether tabs or commas form the actual field separator while
respecting quoted fields, preserving correct content/tag pairs for quoted tabs
and commas. Add regression coverage for both quoted-tab and quoted-comma rows.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a356f943-82f0-4f36-9edd-d577f523c1a1
📒 Files selected for processing (1)
rag/app/tag.py
| delimiter = "\t" if any("\t" in line for line in lines) else "," | ||
|
|
||
| fails = [] | ||
| content = "" | ||
| res = [] | ||
| reader = csv.reader((line + "\n" for line in lines)) | ||
| reader = csv.reader((line + "\n" for line in lines), delimiter=delimiter) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add logging for the new delimiter-selection flow.
This new parser mode is not observable. Add a module logger and record the selected delimiter at debug/info level without logging file contents.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@rag/app/tag.py` around lines 95 - 100, Add a module-level logger and log the
delimiter selected by the parser immediately after the delimiter assignment in
the CSV parsing flow. Include only the selected delimiter in the debug or info
message, and do not log input lines or file contents.
Source: Coding guidelines
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Do not infer the delimiter from any raw tab character.
any("\t" in line for line in lines) runs before CSV quoting is interpreted, so a comma-delimited row such as "alpha\tbeta",tag is incorrectly classified as TAB-delimited. csv.reader then sees the row as one field, causing it to be accumulated or dropped instead of producing a content/tag pair. Detect the delimiter from CSV structure and add regression coverage for quoted tabs and quoted commas.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@rag/app/tag.py` around lines 95 - 100, Update delimiter detection in the CSV
parsing flow around csv.reader so it does not inspect raw tab characters before
quote parsing; determine whether tabs or commas form the actual field separator
while respecting quoted fields, preserving correct content/tag pairs for quoted
tabs and commas. Add regression coverage for both quoted-tab and quoted-comma
rows.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17496 +/- ##
==========================================
- Coverage 94.56% 90.65% -3.91%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 650 -28
- Misses 25 39 +14
- Partials 14 28 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
LGTM |
What problem does this PR solve?
rag/app/tag.pydocuments TAB as the delimiter that separates content from tags:The
.csvbranch does not honour that. It callscsv.readerwith nodelimiterargument, so it always splits on commas regardless of the file's actual delimiter. Two failure modes follow for a genuinely TAB-delimited file:The line is silently dropped. If the content field contains a comma, the row splits into three fields, fails the
len(row) == 2check, and is discarded.the quick, brown fox<TAB>animal,fox-> no rows parsed at all.Content and tags are corrupted. If only the tag field contains a comma, the row splits into exactly two fields by coincidence. The tab and the first tag are left inside the content, and that tag is lost.
hello world<TAB>greeting,demo-> contenthello world\tgreeting, tags["demo"].rag/app/qa.pyalready solves this for its own.csvbranch.tag.pyis its near-twin and was simply missing the same line.Type of change
Change
Detect the delimiter exactly as
qa.pydoes, and pass it tocsv.reader:Verification
Parsing the two cases above through the
.csvbranch, before and after:the quick, brown fox<TAB>animal,fox[](row dropped)("the quick, brown fox", "animal,fox")hello world<TAB>greeting,demo("hello world\tgreeting", "demo")("hello world", "greeting,demo")some content,tag1(plain CSV)("some content", "tag1")Plain comma-delimited files are unaffected.
Note on the heuristic
This mirrors
qa.pydeliberately, so the two twins stay consistent. It is worth being explicit that the heuristic is permissive: a single tab anywhere in the file switches the whole file to TAB parsing, so a comma-delimited file containing one stray tab inside a quoted field would be misread. That tradeoff already exists inqa.pytoday and is not introduced here. If you would prefer a stricter test, the.txtbranch in this same file uses a majority-vote comparison instead, and I am happy to switch both parsers to that in a follow-up.