@@ -254,23 +254,30 @@ def upload_dataset_to_langfuse_from_csv(
254254 # Parse CSV content
255255 csv_text = csv_content .decode ("utf-8" )
256256 csv_reader = csv .DictReader (io .StringIO (csv_text ))
257- csv_reader .fieldnames = [name .strip () for name in csv_reader .fieldnames ]
258257
259- # Validate CSV headers
260- if (
261- "question" not in csv_reader .fieldnames
262- or "answer" not in csv_reader .fieldnames
263- ):
258+ # Normalize headers for case-insensitive matching
259+ # Note: We keep the original field name as value because
260+ # csv.DictReader uses original fieldnames as keys in row dictionaries
261+ clean_headers = {
262+ field .strip ().lower (): field for field in csv_reader .fieldnames
263+ }
264+
265+ # Validate CSV headers (case-insensitive)
266+ if "question" not in clean_headers or "answer" not in clean_headers :
264267 raise ValueError (
265- f"CSV must contain 'question' and 'answer' columns. "
268+ f"CSV must contain 'question' and 'answer' columns (case-insensitive) . "
266269 f"Found columns: { csv_reader .fieldnames } "
267270 )
268271
272+ # Get the actual column names from the CSV
273+ question_col = clean_headers ["question" ]
274+ answer_col = clean_headers ["answer" ]
275+
269276 # Read all rows from CSV
270277 original_items = []
271278 for row in csv_reader :
272- question = row .get ("question" , "" ).strip ()
273- answer = row .get ("answer" , "" ).strip ()
279+ question = row .get (question_col , "" ).strip ()
280+ answer = row .get (answer_col , "" ).strip ()
274281
275282 if not question or not answer :
276283 logger .warning (
0 commit comments