Repository navigation
FEAT: Add a CyberSecEval MITRE scorer - #4691
Open
Siddhant Rajhans (siddhant-rajhans) wants to merge 2 commits into
Open
Siddhant Rajhans (siddhant-rajhans) wants to merge 2 commits into
Siddhant Rajhans (siddhant-rajhans) wants to merge 2 commits into
Conversation
…pipeline Reproduces how CyberSecEval judges MITRE responses: a response its refusal check matches is a refusal, scored without a model call; otherwise an expansion model analyzes the response with CyberSecEval's prompt and a judge model rates the analysis benign or malicious in one word, read in CyberSecEval's order (refusal, then malicious, then benign; a non-empty answer with none is recorded as "else" and not retried, as in CyberSecEval). An empty analysis or judge answer means that call failed, so it is retried and then raised, as CyberSecEvalPromptInjectionScorer treats an empty judge answer. The expansion goes through the prompt normalizer and only its text reaches the judge; a blocked expansion raises ScorerLLMResponseBlockedException. Both models take text and return text, so completion endpoints work. The judge request holds the expansion, so judgment replay needs no model call. Prompts and refusal patterns are CyberSecEval's (MIT), credited in THIRD_PARTY_NOTICES.txt. Signed-off-by: Siddhant Rajhans <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Expansion attempts leave stateful target connections open, risking resource exhaustion, while the missing expansion_target registry reference prevents registry/API construction with a separately named expansion model.
2 open issues
What changed in this PR
Adds CyberSecEvalMitreScorer to complement PyRIT’s existing MITRE dataset loader with CyberSecEval-compatible judging, alongside the prompt-injection scorer from #4440.
Changes:
- Implements refusal detection, expansion and judging, retry handling, and judgment replay.
- Adds verdict metadata, bundled prompts, public exports, and unit coverage.
- Updates scorer documentation and third-party attribution.
| File | Description |
|---|---|
THIRD_PARTY_NOTICES.txt |
Credits CyberSecEval’s MITRE prompts and refusal logic. |
tests/unit/score/test_target_judge.py |
Adds target-validation coverage for the scorer. |
tests/unit/score/test_cyberseceval_mitre_scorer.py |
Tests judging, retries, persistence, replay, and templates. |
tests/unit/models/test_cyberseceval_mitre_verdict.py |
Tests verdict validation and metadata round-trips. |
pyrit/score/true_false/cyberseceval_mitre_scorer.py |
Implements the three-step MITRE scorer and replay support. |
pyrit/score/true_false/cyberseceval_mitre_parser.py |
Implements benchmark refusal detection and verdict parsing. |
pyrit/score/__init__.py |
Exports the scorer and helper functions lazily. |
pyrit/models/score/cyberseceval_mitre_verdict.py |
Defines verdict metadata and its reader/writer. |
pyrit/models/score/__init__.py |
Exports verdict types from the scoring models package. |
pyrit/models/__init__.py |
Exposes verdict types through the public models API. |
pyrit/datasets/score/cyberseceval/cyberseceval_mitre_judge.yaml |
Adds the benchmark’s judge request template. |
pyrit/datasets/score/cyberseceval/cyberseceval_mitre_expansion.yaml |
Adds the benchmark’s expansion request template. |
doc/code/scoring/1_true_false_scorers.py |
Documents the scorer in the paired Python guide. |
doc/code/scoring/1_true_false_scorers.ipynb |
Adds the scorer description to the notebook guide. |
doc/code/scoring/0_scoring.ipynb |
Adds the scorer to the displayed catalog table. |
Review effort: Balanced
Each expansion attempt opened a new conversation and never released it, so a stateful target kept a session open per attempt, retries included. The attempt now releases it afterwards, with the handling score_value_with_llm uses for the judge's fresh sessions: a failed release is logged and never replaces the attempt's result or error, and a cancellation stays a cancellation. expansion_target is now a TARGET entry in ScorerIdentifier's constructor_references, beside source and trace_source, so ScorerRegistry resolves it by name, as it does chat_target. Signed-off-by: Siddhant Rajhans <[email protected]>
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
PyRIT loads CyberSecEval's MITRE dataset but not the benchmark's judging, so a run on that dataset cannot report CyberSecEval's malicious rate. This PR adds
CyberSecEvalMitreScorer, a true/false scorer that reproduces the benchmark's three MITRE judging steps. With #4440 it closes #4339, and it follows the conventions settled in #4440.process_judge_promptbuilds. The answer is read in CyberSecEval's order, malicious before benign, and the score is True for malicious. A non-empty answer with neither word is recorded aselseand not retried, as in CyberSecEval.CyberSecEvalMitreVerdict:refusal,malicious,benignorelse), from which CyberSecEval'sbenign_percentagecan be computed.ScorerLLMResponseBlockedException.THIRD_PARTY_NOTICES.txt. The true/false scorer notebook gets a short description, and the scorer table in0_scoring.ipynblists the new scorer.Validation. Qwen2.5-7B-Instruct answered the 1000 MITRE prompts at temperature 0, and Qwen2.5-72B-Instruct-AWQ, as expansion and judge model, judged them with CyberSecEval's own code. Against that run, this scorer:
CyberSecEval's optional
cot_end_tokensmode, which judges a response's reasoning and its final answer separately, is not reproduced.