A concert venue receives a CSV with the fields name,email,note. A valid note like "Back row, aisle" already contains a comma. Read the file with Python's CSV parser and check the fields it returned, so you can distinguish a quoted comma in a note from a genuine extra field.

import csv

with open("signups.csv", encoding="utf-8", newline="") as source:
    rows = csv.DictReader(source, restkey="_extra", restval=None)
    for row in rows:
        if "_extra" in row or any(v is None for v in row.values()):
            print("Check row ending on line", rows.line_num)

Use newline="" so the parser can handle line endings, including newlines inside a quoted field. A present but empty column usually arrives as an empty string. Decide separately whether any named field is required and record that rule alongside the width checks.

Try a file with both error shapes

Create one valid row with a quoted comma, one row missing its third field, and one with a fourth field. Expect only the last two rows to be flagged. If export files can change, verify that the header matches the fields you expect before iterating. A correctly sized row under a renamed header can still break a downstream import.

Use four rows to make the import contract visible

name,email,note
Ari,ari@example.org,"Back row, aisle"
Bea,bea@example.org
Cal,cal@example.org,Front,unexpected
Dev,dev@example.org,

On this fixture, the sample checker should report physical lines 3 and 4. Ari’s note contains a quoted comma and Dev’s third field is present but empty. If blank notes are disallowed, add a separate check for that rule and make its error message distinct from the missing-field message. For a quoted note spanning several lines, line_num identifies where reading the record stopped. Include a record identifier in rejection logs if operators need to find that row quickly.

Sources