Skip to content

Scorer composition (PR C): roll pure-composition API out to remaining LLM scorers (3/3)#2157

Open
romanlutz wants to merge 4 commits into
microsoft:mainfrom
romanlutz:romanlutz-scorer-composition-rollout-clean
Open

Scorer composition (PR C): roll pure-composition API out to remaining LLM scorers (3/3)#2157
romanlutz wants to merge 4 commits into
microsoft:mainfrom
romanlutz:romanlutz-scorer-composition-rollout-clean

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Summary

Final PR (3/3) of the scorer-architecture refactor ("Option 5 — scorer-owned composition"), following #2125 (ResponseHandler + internal round-trip helper) and #2146 (TrueFalse pure-composition API + CallableResponseHandler), both now merged to main.

This rolls the pure v1.0 composition API out to the remaining LLM-based scorers and removes the last transitional forwarder. Each migrated scorer now stores chat_target + system_prompt + a response_handler and calls the internal _run_llm_scoring_async(...) helper directly, instead of the base Scorer._score_value_with_llm_async forwarder (now deleted).

Scorers migrated

  • SelfAskQuestionAnswerScorer
  • SelfAskRefusalScorer
  • SelfAskCategoryScorer
  • SelfAskGeneralTrueFalseScorer
  • SelfAskScaleScorer
  • SelfAskLikertScorer
  • SelfAskGeneralFloatScaleScorer
  • InsecureCodeScorer

Details

  • Float-scale scorers bake numeric_value=True into the default JsonSchemaResponseHandler; the schema is injected into the default handler only (a caller-supplied handler owns its own contract). Identifiers read response_handler.response_schema.
  • Preset construction moves to from_* factories (from_scale_arguments, from_likert_scale, from_content_classifier, from_question) with module-level render_*_system_prompt and load_scale_arguments helpers mirroring the TrueFalse precedent from Scorer composition (PR B): TrueFalse pure-composition API + CallableResponseHandler #2146.
  • Deletes the transitional Scorer._score_value_with_llm_async forwarder from the base class.
  • Migrates first-party consumers off the removed legacy constructors: crescendo, tree_of_attacks, fairness_bias (docstring example), fuzzer, and the scorer initializer registrations.

Breaking changes (v1.0)

Legacy scorer constructors (e.g. SelfAskScaleScorer(scale_arguments_path=...), SelfAskLikertScorer(likert_scale=...), SelfAskCategoryScorer(content_classifier_path=...), SelfAskRefusalScorer(refusal_system_prompt_path=...)) are replaced by the composition __init__ plus from_* factories. This is an intentional v1.0 breaking change; no deprecation shims remain.

Testing

  • tests/unit/score: 1311 passed, 16 skipped
  • tests/unit/executor + tests/unit/setup (touched consumers): 1249 passed, 22 skipped
  • ruff check, ruff format --check, ty check pyrit: clean

Migrate the remaining LLM-based scorers off the transitional
Scorer._score_value_with_llm_async forwarder to the pure v1.0 composition
API and delete the base forwarder. Each scorer now stores
chat_target + system_prompt + response_handler and calls
_run_llm_scoring_async directly.

Scorers migrated:
- SelfAskQuestionAnswerScorer
- SelfAskRefusalScorer
- SelfAskCategoryScorer
- SelfAskGeneralTrueFalseScorer
- SelfAskScaleScorer
- SelfAskLikertScorer
- SelfAskGeneralFloatScaleScorer
- InsecureCodeScorer

Float-scale scorers bake numeric_value=True into the default
JsonSchemaResponseHandler; identifiers read response_handler.response_schema.
Preset construction moves to from_* factories (from_scale_arguments,
from_likert_scale, from_content_classifier, from_question) with module-level
render_*_system_prompt and load_scale_arguments helpers.

Also migrate first-party consumers off the removed legacy constructors:
crescendo, tree_of_attacks, fairness_bias (docstring example), fuzzer, and
the scorer initializer registrations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2

rlundeen2 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Can you link you design gist? (update: found it, but it is convenient to have here :))

@@ -53,7 +53,7 @@ async def test_likert_scorer_accepts_float_string_score_value(
chat_target.get_identifier.return_value = get_mock_target_identifier("MockChatTarget")
chat_target.send_prompt_async = AsyncMock(return_value=[scorer_likert_float_response])

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.

docs for likert and category need an update because they need a system prompts

The PR changed the public constructors but did not update the executable doc notebooks (.py + paired .ipynb), which per docs.instructions.md are run end-to-end. These will now raise at construction time:

May be worth re-executing

@@ -156,18 +327,4 @@ async def _score_piece_async(self, message_piece: MessagePiece, *, objective: st
return [score]

def _validate_scale_arguments_set(self, scale_args: dict[str, Any]) -> None:

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.

Can we get rid of this function and similarly (for likert) _likert_scale_description_to_string

chat_target: PromptTarget | None = None,
system_prompt: SeedPrompt | str | None = None,
response_handler: ResponseHandler | None = None,
min_value: int = 1,

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.

Nit: Should we get rid of min value and max value? Not sure, but if you pass in the system prompt they're ignored. I am on the fence.

Copilot AI added 2 commits July 10, 2026 10:01
Covers chat_target=None guards, system_prompt str/invalid-type resolution, likert/scale/category system-prompt assembly validation, and refusal score_category normalization across the 7 migrated LLM scorers so diff-cover clears the 90 percent gate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Migrate all doc notebooks that constructed LLM scorers via the legacy keyword API (SelfAskTrueFalseScorer(true_false_question=...), SelfAskLikertScorer(likert_scale=...), SelfAskCategoryScorer(content_classifier_path=...)) to the new composition classmethods (from_question / from_likert_scale / from_content_classifier, with TrueFalseQuestion.from_yaml for path-based questions). Both paired .py and .ipynb files updated in sync.

Freshly re-executed the core scorer/target notebooks (scoring/1, scoring/2, scoring/4, targets/1) to validate the new API end-to-end and refresh outputs. Remaining notebooks are code-migrated with preserved outputs (they require infra/targets not available in this environment).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 self-assigned this Jul 10, 2026
Freshly re-ran executor/3_attack_configuration, executor/6_benchmark, executor/7_promptgen, targets/3_openai_image_target, and targets/round_robin_target to refresh outputs under the migrated scorer API. Normalized memory image paths in the image-target notebook to the repo-standard ./dbdata/ form.

The Sora video notebook (targets/4) requires video-generation access unavailable here (execution aborted, left code-migrated). executor/8_modality_feedback executed successfully but was left at its code-migrated outputs to avoid a +7MB notebook-size increase. The 5 hard-infra notebooks (multi_turn, realtime, playwright, http, azure_sql) remain code-migrated with preserved outputs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants