Skip to content

FIX: Use the canonical leading-comment rule when loading classifier CSVs - #3291

Queued
Chen Yufeiyang (feiiiiii5) wants to merge 8 commits into
microsoft:mainfrom
feiiiiii5:fix/classifier-comment-block
Queued

Chen Yufeiyang (feiiiiii5) wants to merge 8 commits into
microsoft:mainfrom
feiiiiii5:fix/classifier-comment-block

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Description

Both local classifier scorers hand-rolled how they skip a dataset's leading # comment lines, and neither matched HumanLabeledDataset._read_leading_comment_block (the rule settled in #2983):

  • LocalRefusalClassifierScorer dropped every line starting with #, including data rows and lines inside quoted cells. refusal.csv in the package already has one training response truncated by this (4161 vs 4257 characters, row 70); a data row whose first cell starts with # was silently dropped altogether.
  • LocalViolenceClassifierScorer skipped only the first line, so a file with two or more leading # lines (or a blank line before the comments) quietly loaded zero rows and then failed with a misleading "not enough training data" ValueError.

Both loaders now use a shared strip_leading_comment_block() helper (pyrit/common/csv_helper.py) with the same scan as the canonical reader: only the leading comment/blank block is removed; everything from the first content line on is data. Dataset bytes, hash pins and _RECIPE_VERSION are untouched.

Tests and Documentation

New regressions in tests/unit/score/test_local_refusal_classifier_scorer.py and test_local_violence_classifier_scorer.py: both fail on main (a #-prefixed row dropped / rows read as empty) and pass with the fix. Relevant suite green: the two classifier test files (-k loader/pin selection; the real-tokenizer cases need a working transformers env), test_human_labeled_dataset.py, test_scorer_eval_csv_schema.py; ruff check / ruff format --check clean on the touched files (0.17.0, matching pre-commit). No JupyText sample is involved and no documentation change is needed since the rule itself is unchanged.

The two local classifier scorers hand-rolled how they skip a dataset's leading '#' comment lines, and neither matched HumanLabeledDataset._read_leading_comment_block:

- LocalRefusalClassifierScorer dropped every line starting with '#', including data rows and lines inside quoted cells; the packaged refusal.csv already has one training response truncated by this (4161 vs 4257 characters).
- LocalViolenceClassifierScorer skipped only the first line, so a file with several leading '#' lines (or a blank line first) quietly loaded zero rows and then failed with a misleading not-enough-training-data error.

Both now use a shared strip_leading_comment_block() helper with the canonical scan: only the leading comment/blank block is removed, everything from the first content line on is data.
Comment thread pyrit/common/csv_helper.py Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c89266be-249b-4382-bfd3-0a3b3c449ae3
Keep universal newline recognition without translating CR or CRLF in the leading-comment scan and both classifier CSV readers. Cover mixed quoted-cell and record separators, blank/comment prefixes, and non-newline separators.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c89266be-249b-4382-bfd3-0a3b3c449ae3
Preserve the contributor's concurrent fix and mixed-newline regression tests alongside the expanded separator matrix and latest main.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c89266be-249b-4382-bfd3-0a3b3c449ae3
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c89266be-249b-4382-bfd3-0a3b3c449ae3
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 20, 2026
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 20, 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants