CSVToDocument accepts an unsupported conversion_mode and silently converts in row mode

オープン 初心者向け
#13,070 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Lesereingrape がすでに取り組んでいます。

2026年10月2日 から。

  • #3 @Harsh23Kashyap による — オープン
  • #13084 @Lesereingrape による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

haystack/components/converters/csv.py の CSVToDocument.init から始め、haystack/components/converters/xlsx.py の 82-86 行目とそのバリデーションを比較してください。conversion_mode の実行時バリデーションを追加し、準備したテストでサポートされていない値を網羅して、有効なファイルモードと行モードが引き続き機能し、無効な値が構築時に失敗することを確認してください。

索引モデルが issue の本文から書いたものです。

説明

P3

Describe the bug

CSVToDocument never validates conversion_mode. __init__ stores the value as given (haystack/components/converters/csv.py:75) and its "Basic validation" block only checks delimiter and quotechar (line 79). run() then dispatches on a single equality test against "file" (line 142), so any other value falls into the row branch.

The parameter is annotated Literal["file", "row"], but at runtime a typo — or a value that differs only in case or trailing whitespace, which is common when the component is loaded from a saved pipeline YAML — is accepted and silently changes what the converter produces: one Document per CSV row instead of one per file.

Error message

No error is raised for conversion_mode="Rows"; the pipeline just converts differently. When content_column is not passed to run(), the failure that eventually surfaces names a mode the caller never configured, which points the reader at the wrong branch:

ValueError: CSVToDocument(row): 'content_column' is required in run() when conversion_mode='row'.

Measured on main at 9f31fb4b, for the same three-row CSV:

conversion_mode run(..., content_column="title") documents produced
"file" documented value 1 — 'title,author\nDune,Frank Herbert\nNeuromancer,Gibson\n'
"Rows" typo 2 — 'Dune', 'Neuromancer'
"FILE" case typo 2 — 'Dune', 'Neuromancer'
"row " trailing space ValueError quoting conversion_mode='row'

Expected behavior

Constructing the component with a value outside Literal["file", "row"] should fail fast in __init__, the way the sibling XLSXToDocument already validates its own Literal parameters in its constructor (haystack/components/converters/xlsx.py:82-86 checks table_format and link_format):

ValueError: CSVToDocument: unsupported conversion_mode 'Rows'. Choose 'file' or 'row'.

That keeps the documented type contract true at runtime and turns a silent per-row conversion into an immediate, actionable error.

To Reproduce

from haystack.components.converters import CSVToDocument
from haystack.dataclasses import ByteStream

csv = "title,author\nDune,Frank Herbert\nNeuromancer,Gibson\n"
sources = [ByteStream.from_string(csv)]

# 1. silent wrong behaviour: "Rows" != "file", so run() takes the row branch
docs = CSVToDocument(conversion_mode="Rows").run(sources=sources, content_column="title")["documents"]
print(len(docs))        # 2, not 1
print(docs[0].content)  # 'Dune'

# 2. misleading error message naming a mode that was never configured
CSVToDocument(conversion_mode="row ").run(sources=sources)
# ValueError: CSVToDocument(row): 'content_column' is required in run() when conversion_mode='row'.

Additional context

conversion_mode is part of the serialized component config, so a misspelled value can be loaded from a saved pipeline YAML without ever passing through a type checker, and the wrong-mode output flows into the rest of the indexing pipeline unnoticed.

I read the source while looking for the same unvalidated-Literal pattern the XLSXToDocument constructor guards against, and have a two-line validation plus tests prepared locally (reproduced RED on main, GREEN with the change).

FAQ Check

System:

  • OS: Windows 11
  • Haystack version: 3.3.0-rc0 (editable install of main @ 9f31fb4b), Python 3.11.14
主要言語
Python
スター
27.1k
フォーク
3.5k
平均マージ
1日 8時間
マージ済み PR(30日)
239

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

deepset-ai/haystack のほかの issue

deepset-ai/haystack の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。