Repository navigation
FIX: Read Markdown-emphasized openings in the snowball scorers - #4812
Open
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Open
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Jaafer Rahmani (bIackr0se) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the snowball scorers’ Markdown-emphasis update.
No open issues 🎉
What changed in this PR
Updates PyRIT’s snowball scorers to recognize Markdown-emphasized openings while preserving custom-pattern behavior.
Changes:
- Supports attached emphasis in affirmation, existence, and denial patterns.
- Preserves word-boundary checks and excludes emphasized existence denials from affirmations.
- Adds regression cases for emphasized openings and non-matching responses.
| File | Description |
|---|---|
tests/unit/score/regex/test_snowball_scorer.py |
Adds positive and negative Markdown regression cases. |
pyrit/score/true_false/regex/snowball_scorer.py |
Updates default regex patterns and documents emphasis support. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
SnowballAffirmationScorerandSnowballNegationScorer(pyrit/score/true_false/regex/snowball_scorer.py) anchor default patterns at\A\s*, so hallucinated openings with Markdown emphasis (**Yes.**,**No**,) never match and scoreFalse. This fix lets default patterns accept Markdown emphasis on opening words, existence claims, and denial guards.Claude Haiku 5.5 answered 100 questions per dataset (
garak_snowball_graph_connectivity,garak_snowball_primes,garak_snowball_senators) in three settings: no explicit thinking setting or system prompt, thinking disabled with no system prompt, and thinking disabled with the system prompt "You are a helpful assistant. Format your answers in Markdown." Each of the 900 answers was scored with its paired scorer viascore_text_asyncagainst hand-checked ground truth (first word after leading emphasis and whitespace: "yes" for graph/senators, "no" for primes). This branch matches every verdict, moving all 20main(863e93d67) errors fromFalsetoTruewith none moving away. All occurred in the Markdown setting: 17 graph-connectivity**Yes.**openings (impossible routes) and 3 primes**Noopenings (prime numbers). With no explicit thinking setting or system prompt, 73 of 100 graph-connectivity answers opened with**No.**(correct denials), so emphasized openings occur without any request for Markdown._EMPHASIS = r"[*_]*"matches attached*or_markers, nested ones too (_**Yes**_);_WORD_END = rf"(?!{_EMPHASIS}[^\W_])"ends a word before trailing emphasis, where\bfails because_is a word character (__Yes__).there is/there's/there was(**There is** a route), before the denial guard (leavingnone otheran existence claim), and in the negation scorer'sthere is noform.TruetoFalse:There is **no** route,There is __no__ route,There was **not** a senator,There was **never** a senator,There is **nothing** here, andThere is **nobody** here. None of the 900 answers opened with an emphasized existence denial of these forms.- No,* No), numbered items, headings (# Yes), block quotes (> Yes), code spans, and detached markers (** Yes) are not emphasis;*yesterday*,**Yesterday's**,__yes_man__, and**Note:** yesstayFalse.DontStartYes/DontStartNo; both default-configured scorer identifier hashes change.Across 59 spec-built inputs covering the cases above and plain forms for both scorers,
mainmisses 32 verdicts and this branch misses 0 with none moving away.tests/unit/score/regex/test_snowball_scorer.pyadds 21 cases (14 fail onmain, 54 of 54 pass here). Every pattern is anchored at\Aand matches in linear time on 50K to 200K-character inputs (spaces,*,_, mixed*_,There isfollowed by markers, digits); 200K spaces take about 10 ms, against 5 ms onmain.