Repository navigation
Description
Following up on the note Roman Lutz (@romanlutz) left in #1867: the Scorer base class carries machinery that only LLM-backed scorers use, and it would be cleaner to separate that out. Opening this to propose a concrete shape and get direction before writing code.
The problem
Scorer currently owns several members that are only meaningful when the scorer calls an LLM:
_score_value_with_llm_async(...)(the JSON/parser plumbing, retries, system-prompt wiring)- the
chat_targetparameter on__init__and theTARGET_REQUIREMENTSvalidation it triggers get_chat_target()and the_prompt_targetattribute convention- the
prompt_targetpromotion inside_create_identifier
About half of the current scorers never use any of this. The regex family (RegexScorer, CredentialLeakScorer, PathTraversalOutputScorer, ShellCommandOutputScorer, SqlInjectionOutputScorer, XssOutputScorer) and the keyword family (AnthraxKeywordScorer, FentanylKeywordScorer, MethKeywordScorer, NerveAgentKeywordScorer), plus SubStringScorer and MarkdownInjectionScorer, are pure rule-based scorers. They inherit the LLM surface but never touch it.
The LLM-using scorers are the self_ask_* family and InsecureCodeScorer (11 in total). That split is stable and unlikely to change, so the concern is a good candidate for its own type.
Why a mixin rather than an intermediate base
The existing type hierarchy already discriminates on output shape: TrueFalseScorer vs FloatScaleScorer, and scorer_type keys off that via isinstance. "Uses an LLM" is orthogonal to "returns true/false vs float", so folding it into the linear hierarchy would force a combinatorial split (LLMTrueFalseScorer, LLMFloatScaleScorer, and so on).
A mixin composes cleanly instead:
class LLMScorerMixin:
"""Owns chat-target wiring and _score_value_with_llm_async for LLM-backed scorers."""
...
class SelfAskTrueFalseScorer(LLMScorerMixin, TrueFalseScorer):
...
class InsecureCodeScorer(LLMScorerMixin, FloatScaleScorer):
...The base Scorer keeps only what every scorer needs: the validator, the score_async / _score_piece_async interface, memory access, identifier construction, and the batch/evaluate helpers.
Proposed phasing
To keep each PR reviewable and avoid a single large diff:
- Introduce
LLMScorerMixinwith the moved members, and have the LLM scorers inherit from it. Keep thin delegating shims onScorermarked for 0.16.0 removal so nothing breaks for downstream code that subclassedScorerdirectly and called_score_value_with_llm_async. - Migrate the internal LLM scorers to the mixin and update their identifier construction.
- Remove the shims from
Scoreronce the deprecation window closes.
Each phase is a separate PR. Phase 1 is additive and backward-compatible.
Open questions
- Mixin versus intermediate base: I lean mixin for the orthogonality reason above. If you would rather keep a linear hierarchy, that changes the shape substantially, so worth settling first.
- Does
TARGET_REQUIREMENTSand thechat_targetvalidation move fully into the mixin, or does the base keep a no-op default soevaluate_async/ batch helpers that read_prompt_targetviagetattrkeep working unchanged? - Naming:
LLMScorerMixin,LLMScorer, or something else that fits PyRIT conventions. - Deprecation-shim approach in Phase 1 versus a single atomic move. The shim path is safer for downstream subclasses but adds temporary surface. Do you have a preference given where 0.16.0 is in its cycle?
Happy to start on Phase 1 once the mixin versus base question is settled.
Activity
romanlutz commentedon Jul 9, 2026
I have a 3-part series of PRs. #2125 is merged. #2146 is out and I have the third one already written.
See https://gist.github.com/romanlutz/583ba7017b778d1a6a105fdbeb15dd37 for details on the plans.
immu4989 commentedon Jul 9, 2026
Thanks for pointing me to the series and the gist. Having read #2125 and the Option 5 notes, I agree the composition approach is the better call. A
ResponseHandlerobject localizes the LLM scoring concern in one place, whereas the mixin I sketched here still spreads that surface across the MRO of every LLM scorer. Composition also gives you theCallableResponseHandlerescape hatch cleanly, which is a nicer home for the LlamaGuard parser than theresponse_parserkwarg was.Happy to close this in favor of your series.
One offer: the gist notes PR C rolls the pattern to the remaining LLM scorers, one commit each. If it would help to parallelize that, I am glad to take a few of them (
self_ask_refusal,self_ask_category,self_ask_likert,self_ask_scale) against the API PR B establishes, following your first migration as the template. Only if that is useful to you, otherwise I will leave the series in your hands.romanlutz commentedon Jul 9, 2026
I'm trying to wrap this up this week and will be faster doing it myself with the AI agent but if you want to review the PR (should be out any moment now) please do so!