Skip to content

FEAT: Add a CyberSecEval MITRE scorer - #4691

Open
Siddhant Rajhans (siddhant-rajhans) wants to merge 2 commits into
microsoft:mainfrom
siddhant-rajhans:feat/cyberseceval-mitre-scorer
Open

Siddhant Rajhans (siddhant-rajhans) wants to merge 2 commits into
microsoft:mainfrom
siddhant-rajhans:feat/cyberseceval-mitre-scorer

Conversation

@siddhant-rajhans

Copy link
Copy Markdown
Contributor

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.

  • Refusals: a response that CyberSecEval's refusal check matches is a refusal. CyberSecEval neither expands nor judges it, so it is scored without a model call.
  • Expansion and judge: otherwise an expansion model analyzes the response with CyberSecEval's expansion prompt, and a judge model rates that analysis benign or malicious in one word, with the request CyberSecEval's process_judge_prompt builds. 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 as else and not retried, as in CyberSecEval.
  • Verdict: CyberSecEval reports refusal, malicious and benign counts separately, so the score metadata carries the verdict (CyberSecEvalMitreVerdict: refusal, malicious, benign or else), from which CyberSecEval's benign_percentage can be computed.
  • Failed calls: an empty analysis or judge answer means that call failed, so it is retried and then raised, the way FEAT: Add a CyberSecEval prompt injection scorer #4440 treats an empty judge answer. The expansion goes through the prompt normalizer and only its text reaches the judge; a blocked expansion raises ScorerLLMResponseBlockedException.
  • Targets and replay: both models take text and return text, so completion endpoints work, and the expansion model defaults to the judge model. The judge request holds the expansion, so judgment replay re-reads a stored verdict without a model call.
  • Credits and docs: the prompts and refusal patterns are CyberSecEval's (MIT, at the revision the loader pins), credited in THIRD_PARTY_NOTICES.txt. The true/false scorer notebook gets a short description, and the scorer table in 0_scoring.ipynb lists 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:

  • finds the same 73 refusals;
  • builds the same request as CyberSecEval for all 927 expansions, and for all 927 judge calls when given CyberSecEval's expansions;
  • reads CyberSecEval's judge answers into the same verdict for all 1000 (malicious 71.9%);
  • matches 976 of 1000 verdicts end to end with its own model calls (malicious 72.7%). The expansions are long and do not repeat exactly between runs even at temperature 0 (449 of 927 came out identical), so the judge read different text for the rest. For scale, CyberSecEval's own code at its default sampling disagrees with its temperature-0 run on 82 of 1000.

CyberSecEval's optional cot_end_tokens mode, which judges a response's reasoning and its final answer separately, is not reproduced.

…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]>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 01:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

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.

FEAT: Scorers that reproduce CyberSecEval's prompt injection and MITRE judging

2 participants