MAINT Decompose scorer execution policy and result finalization
@iamhaseebn is already working on this.
Since Aug 22, 2026.
Assessment
This issue has not been assessed yet.
Description
Is your feature request related to a problem? Please describe.
Scorer.score_async in pyrit/score/scorer.py is the central execution path for every scorer and currently combines several distinct policy stages in roughly 121 lines and 27 branches:
- structured-refusal and partial-content substitution;
- validator and role-filter handling;
- error-result skip policy;
- objective inference;
- subclass score execution;
- blocked-scorer and exception policy;
- fallback-score construction;
- score validation;
- ephemeral message-piece foreign-key cleanup;
- persistence to memory.
All of these responsibilities belong at the scorer layer, but keeping their decision matrix in one method makes edge cases difficult to audit and extend. Changes to blocked content, structured refusals, or persistence can unintentionally affect every scorer and downstream attacks such as Crescendo.
Describe the solution you'd like
Keep Scorer.score_async as the public orchestration entry point, but extract cohesive internal units rather than pass-through wrappers. One possible design is:
- A typed scoring-input/policy decision that produces the effective message, objective, and skip decision.
- A narrowly scoped execution/error-policy step around
_score_async. - A result-finalization helper that applies fallback behavior, validates results, clears ephemeral foreign keys, and persists scores.
The refactor must preserve scorer ownership of these policies and should not move decisions into targets, attacks, or memory.
Describe alternatives you've considered, if relevant
A new service/facade would add an abstraction without clarifying ownership. Extracting every conditional into a tiny helper would reduce method length but increase navigation and leave the policy matrix implicit. A typed intermediate result is preferred because it makes the allowed states and invariants testable.
Additional context
Acceptance and validation should include:
- all scorer unit tests;
- blocked response with and without partial content;
- structured refusal substitution;
skip_on_error_resultand role-filter combinations;- explicit and inferred objectives;
- scorer-owned blocked responses with both raise/fallback policies;
- PyRIT and non-PyRIT exception propagation;
- fallback scores for empty/filtered pieces;
- ephemeral versus persisted message pieces;
- exact memory writes and score validation;
- Crescendo and red-teaming caller tests.
This is a medium-confidence design proposal with high compatibility impact. Please preserve behavior and add matrix-style tests before moving logic.
- Dominant language
- Python
- Stars
- 4.5k
- Forks
- 896
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 155
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/PyRIT
-
Bug: triage help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Bug: triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
BUG: ScorerMetrics.to_json() raises TypeError on the trial_scores array ScorerEvaluator attaches Open
Difficulty 3/5 1-2 days Newbie friendliness 78/100
-
Bug: triage help wanted
Difficulty 3/5 1-2 days Newbie friendliness 75/100
-
Difficulty 4/5 3-5 days Newbie friendliness 68/100
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100