Repository navigation
fix(extraction): don't treat prose-with-commas as CSV - #62
Merged
acidkill merged 1 commit intoJul 15, 2026
Merged
Conversation
_detect_csv_row accepts any single line with >=2 commas and >=3 fields as a headerless CSV row. The only prose guard rejected the row when ALL fields were plain text — so ordinary prose containing one date, price or number in any comma-separated fragment (release notes, meeting summaries, "on 2026-07-08 we rotated the password, and ...") was stored as ContentFormat.CSV_ROW with synthetic col_0/col_1/... fields. Each becomes a spurious entity-cell entry that accumulates and pollutes downstream extraction / recall. Add a prose guard on the headerless branch: if any cell is long (>40 chars) or multi-word (>6 words) the line is prose, not CSV. Real headerless CSV cells are short, token-like values, so the false-negative risk is negligible; genuine short-cell data rows (dates, numbers, currency) still detect. Tests: +2 (prose-with-a-date is rejected; a genuine short-cell row still detects).
| # `col_N` entity-cell entries that pollute downstream extraction. The | ||
| # all-text guard below is not enough on its own: a single date or number | ||
| # in one cell used to slip prose through. | ||
| if any(len(v) > 40 or len(v.split()) > 6 for v in values): |
Contributor
Author
There was a problem hiding this comment.
The two thresholds are deliberately loose: a genuine headerless CSV cell is a short token (a date, a number, a currency code, an id), so > 40 chars or > 6 words only ever trips on free text. It sits in front of the existing all-text guard rather than replacing it, because the gap was specifically that one numeric/date cell was enough to rescue an entire prose line past the all-text check. Happy to tighten to a ≥2-non-text-field rule instead if you'd prefer a structural test over a length heuristic.
acidkill
approved these changes
Jul 15, 2026
acidkill
left a comment
Owner
There was a problem hiding this comment.
no issues found. thanks for your contribution
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.
Hi Toni!
Last of the noise-quality fixes our production usage surfaced — small, but it's a memory-poisoning source that hits anyone feeding free-form text through auto-mode extraction (so, most auto-capture setups).
The problem
_detect_csv_rowtreats any single line with ≥2 commas and ≥3 fields as a headerless CSV row. The only prose guard rejects the row when all fields are plain text — so ordinary prose that happens to contain one date, price or number in any comma-separated fragment slips through. A line like"Met the team on 2026-01-14, reviewed the roadmap, and signed off the budget"is stored asContentFormat.CSV_ROWwith syntheticcol_0/col_1/… fields, each of which becomes an entity-cell entry. Over time these accumulate and surface in recall ascol_0 | col_1 | col_2 …garbage — we saw exactly that in our store's recall output.The fix
One guard on the headerless branch: if any cell is long (
> 40chars) or multi-word (> 6words), the line is prose, not CSV. Real headerless CSV cells are short, token-like values, so the false-negative risk is negligible — genuine short-cell data rows (dates, numbers, currency) still detect. The existing all-text guard stays; this just closes the "one number rescues the whole prose line" gap in front of it.Type of Change
Testing
TestCsvProseGuard(2 cases): a prose line with an embedded date is now rejected, and a genuine short-cell row (2026-01-01,500,USD) still detects.main): 6,082 passed, 33 skipped in ~35 s (-n0), clean exit.ruffandmypyclean on the touched file.Checklist
CHANGELOG.md— proposed entry below; happy to fold it into the branch.Optional extra hardening (open to discussion)
If you'd rather be stricter, a headerless single-line row could additionally require ≥2 non-text field types, or its confidence (currently
0.7) could be dropped below the encode threshold — I kept the change minimal here, but I'm glad to adjust to whatever bar you prefer.Proposed
CHANGELOG.mdentry (Unreleased / Fixed)Robert