DEV Community

CloudGPU
CloudGPU

Posted on

Fail an AI CSV import before duplicate column names become keys

Open the export with newline="" and UTF-8 BOM handling, then pass the file to csv.reader. Take the first logical record and collect one-based positions for every raw heading. Stop before any name-keyed mapping when a heading is empty or repeats. This also avoids treating a quoted comma as a delimiter.

For a synthetic regression fixture, use clip_id,status,status followed by 07,cut,approved. The checker should report {"status":[2,3]} and exit 1. Change the header to clip_id,edit_status,review_status only after confirming the semantics. The sample now exits 0.

Add a second fixture with a quoted comma and run both in CI. Make the AI step consume only accepted, approved sample rows. This preflight does not validate body rows or semantic correctness.

Method reference: Python 3.12 documentation, csv — CSV File Reading and Writing

Drafted with AI assistance. All examples are synthetic.

Top comments (0)