Skip to content

fix(datamodel): keep plain-text fallback for .txt/.text files in CSV sniffer - #5633

Open
fanjiahe wants to merge 1 commit into
docling-project:mainfrom
fanjiahe:fix/txt-vba-csv-detection
Open

fanjiahe wants to merge 1 commit into
docling-project:mainfrom
fanjiahe:fix/txt-vba-csv-detection

Conversation

@fanjiahe

Copy link
Copy Markdown
Contributor

Fixes #5631

Summary

  • Updated _DocumentConversionInput._detect_csv() in docling/datamodel/document.py to accept ext: Optional[str] = None (matching _detect_latex() and _detect_calendar()), returning None when the file extension is in FormatToExtensions[InputFormat.MD] (e.g. .txt, .text).
  • Passed obj_ext from _guess_format() into _detect_csv(content, obj_ext) so plain-text files containing commas or quoted literals (such as VBA source in .txt) fall back to ext/plain / InputFormat.MD instead of being misclassified as InputFormat.CSV, while extensionless CSV streams and .csv files continue to be detected as InputFormat.CSV.
  • Added parameterized regression cases in ests/test_input_doc.py ( est_guess_format_csv_does_not_hijack_plain_text).

Verification

  • Ran
    uff check and
    uff format --check on docling/datamodel/document.py and ests/test_input_doc.py — passed.
  • Ran pytest tests/test_backend_csv.py -q — 79 passed.
  • Executed est_guess_format_csv_does_not_hijack_plain_text directly across .txt, .md, .text, .csv, and extensionless inputs in the local environment.

AI-assisted contribution (human-reviewed and verified locally).

…sniffer

Signed-off-by: fanjiahe <fanjiahe@mail.ustc.edu.cn>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 06:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @fanjiahe, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working csv issue related to csv backend markdown issue related to markdown backend mimetype plain text issue related to plain text input (read by the Markdown backend) priority:medium labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit bb62c82f99. The analysis read the diff only. It did not run code from this pull request.

The PR makes the CSV content sniffer skip files that have a plain-text extension such as .txt or .text. These files now fall back to InputFormat.MD and no longer get detected as InputFormat.CSV. It adds parameterized tests for this.

Topic labels added: bug, csv, plain text, mimetype, priority:medium, markdown.

CI safety: no concern found. A maintainer must still approve CI.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at bb62c82f99. It read the code and did not run it.

The fix works for .txt files, but it changes detection for every .txt file. A .txt file that holds real CSV data used to be read as CSV and now becomes Markdown. The tests do not cover this, and the PR does not say it. The reviewer must decide whether this change is intended.

A maintainer makes the merge decision. This review never approves the pull request.

The mime type of a CSV file, or None if the content does
not match any of the format.
"""
if (ext or "").lower() in FormatToExtensions[InputFormat.MD]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: .txt files with real CSV content no longer convert as CSV

A .txt path has no mime from its extension. _mime_from_extension skips MD because txt is also an XML_USPTO extension. _guess_format then sniffs the content, and _detect_csv used to run for .txt files. With this check, a .txt file that holds comma-separated rows returns None. _guess_format then falls back to text/plain and InputFormat.MD. Such a file was InputFormat.CSV before. It is now a Markdown text blob, with no table.

This may be the wanted trade-off, because the issue is about VBA source in .txt. But the PR does not say it and no test covers it. The .txt case in the new test uses VBA source. The notes.text case does not exercise the change: text is in the MD extensions, so _mime_from_extension already returns text/markdown and _detect_csv is never called. The .md case is the same.

Please confirm that .txt files with CSV data should now convert as Markdown. If they should, say so in the PR description. Also add a .txt test with clean CSV content that shows the new result. If they should stay CSV, use a narrower check than the extension alone.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 27, 2026
@github-actions github-actions Bot mentioned this pull request Nov 27, 2026
3 tasks done
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working csv issue related to csv backend markdown issue related to markdown backend mimetype plain text issue related to plain text input (read by the Markdown backend) priority:medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plain-text VBA source misidentified as CSV, causing conversion failure

2 participants