Skip to content

fix: reject an unsupported conversion_mode in CSVToDocument - #13084

Draft
Lesereingrape wants to merge 3 commits into
deepset-ai:mainfrom
Lesereingrape:fix/csv-conversion-mode-13070
Draft

Lesereingrape wants to merge 3 commits into
deepset-ai:mainfrom
Lesereingrape:fix/csv-conversion-mode-13070

Conversation

@Lesereingrape

@Lesereingrape Lesereingrape commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What happened

CSVToDocument declares conversion_mode: Literal["file", "row"] but never validates it — __init__ only checks delimiter and quotechar under a # Basic validation comment. run() then dispatches with if self.conversion_mode == "file": … and everything else falls through into the row branch. So a mistyped mode is not an error; it quietly changes what the component produces.

Measured on 8a5406ee with a 2-row CSV (text,author + 2 data rows), D:/hs_lane/env python:

'file'   -> 1 doc(s) :: ['text,author\r\nNice app,A\r\nB']
'row'    -> 2 doc(s) :: ['Nice app', 'Buggy']
'Rows'   -> 2 doc(s) :: ['Nice app', 'Buggy']      # silent mode switch
'file '  -> RAISED ValueError: CSVToDocument(row): 'content_column' is required in run() when conversion_mode='row'.
''       -> RAISED ValueError: CSVToDocument(row): 'content_column' is required in run() when conversion_mode='row'.

Two caller-visible problems in that output:

  • conversion_mode="Rows" returns a different document count and different content shape than asked for, with no signal at all. Downstream Document consumers just see more, shorter documents.
  • A value that is only wrong by a trailing space raises an error that names a mode the caller never set. The message says when conversion_mode='row', which sends the user to look at their content_column argument instead of at their typo.

What changed

Validate the Literal in __init__, the way the sibling converter in the same package already validates its own Literal fields — XLSXToDocument raises for an unknown table_format (haystack/components/converters/xlsx.py:82-83) and for an unknown link_format (:84-86). The check joins the existing # Basic validation block, so the component now fails at construction, where the bad argument is visible, rather than at run().

Nothing about the two valid modes changed: "file" still yields one Document per file and "row" still requires content_column in run().

How it was checked

Added to test/components/converters/test_csv_to_document.py, next to the existing test_init_validates_delimiter_and_quotechar:

  • test_init_rejects_an_unknown_conversion_mode — "Rows" raises, matched on the message.
  • test_init_rejects_a_conversion_mode_that_only_differs_in_whitespace_or_case — "file " and "" raise.
  • test_init_accepts_both_documented_conversion_modes — control: the two valid values still construct.
$ python -m pytest test/components/converters/test_csv_to_document.py -q   # on an unmodified 8a5406ee + the new tests
2 failed, 18 passed
$ python -m pytest test/components/converters/test_csv_to_document.py -q   # with the fix
20 passed in 0.34s

CSVToDocument is also instantiated by MultiFileConverter, so that file was run before and after: 2 failed, 16 errors on a pristine 8a5406ee worktree and the identical 2 failed, 16 errors with the change — those are optional converter dependencies (pypdf, python-docx) missing in my local environment, not this patch. ruff check and ruff format --check are clean on both changed files. A release note is included (releasenotes/notes/csv-conversion-mode-validation-8f4c2b1d7e9a3056.yaml).

Reported in #13070, which shows the same silent mode switch from the caller side.


Disclosure: this PR was prepared, tested and submitted by an AI agent working on behalf of the account owner.

Related Issues

Proposed Changes:

  • Add the missing conversion_mode check to the existing # Basic validation block in CSVToDocument.__init__, so an unsupported value fails at construction instead of silently falling into the row branch in run().
  • Nothing changes for the two documented modes, and the release note describes only the new ValueError.

How did you test it?

python -m pytest test/components/converters/test_csv_to_document.py -q — 2 failed, 18 passed without the fix, 20 passed with it (details in "How it was checked" above).

Notes for the reviewer

The error message quotes the offending value with !r, which is what makes "Rows" and "file " distinguishable in the message; the existing tests match on it.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

Lesereingrape and others added 2 commits October 2, 2026 18:13
…to row mode

CSVToDocument compared conversion_mode only against "file" in run(), so any
other value selected the row branch: a typo such as "Rows" silently produced
one Document per row instead of one per file, and a value differing only by
trailing whitespace raised an error claiming conversion_mode='row'. Validate
the Literal in __init__, the way the sibling XLSXToDocument already validates
table_format and link_format.
@vercel

vercel Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@Lesereingrape is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/converters
  csv.py
Project Total  

This report was generated by python-coverage-comment-action

@Lesereingrape Lesereingrape changed the title Fix/csv conversion mode 13070 fix: reject an unsupported conversion_mode in CSVToDocument Oct 2, 2026

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

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSVToDocument accepts an unsupported conversion_mode and silently converts in row mode

1 participant