Skip to content

Scorer composition (PR C, 3/3): complete LLM rollout with typed rubrics#2157

Merged
romanlutz merged 10 commits into
microsoft:mainfrom
romanlutz:romanlutz-scorer-composition-rollout-clean
Jul 12, 2026
Merged

Scorer composition (PR C, 3/3): complete LLM rollout with typed rubrics#2157
romanlutz merged 10 commits into
microsoft:mainfrom
romanlutz:romanlutz-scorer-composition-rollout-clean

Conversation

@romanlutz

@romanlutz romanlutz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Design: Scorer architecture refactor design gist

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 owns its target, prompt configuration, and ResponseHandler, then calls _run_llm_scoring_async(...) directly instead of the deleted Scorer._score_value_with_llm_async base-class forwarder.

The final API also introduces typed rubric/configuration objects. Factory methods render the LLM prompt and configure runtime validation, categories, and normalization from the same object, preventing hidden defaults from drifting away from prompt content. Direct custom construction requires the final prompt together with its rubric/configuration.

Scorers migrated

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

Final composition API

  • SelfAskScaleScorer.from_scale(...) uses a NumericRubric; prompt rendering, category, and normalization bounds come from that rubric. Omitting it retains the bundled tree-of-attacks rubric.
  • SelfAskLikertScorer.from_likert_scale(...) uses an immutable LikertScale; configured entries define prompt text, valid returned levels, category, bounds, and normalization.
  • SelfAskGeneralFloatScaleScorer requires a NumericRange for explicit normalization bounds and optional category.
  • SelfAskCategoryScorer.from_content_classifier(...) uses a ContentClassifier; configured categories and boolean relationships are validated inside the retry boundary.
  • SelfAskTrueFalseScorer.from_question(...) renders from a TrueFalseQuestion; custom direct construction requires both prompt and question, while omitting both retains the bundled default.
  • InsecureCodeScorer.from_harm_categories(...) uses the same immutable category snapshot for prompt rendering and score metadata.
  • Prompt templates can be bundled defaults, SeedPrompt instances, or inline Jinja strings where supported. Module-level render_*_system_prompt helpers expose rendering without constructing a scorer.

Other details

  • Float-scale scorers set numeric_value=True on their default JsonSchemaResponseHandler. Embedded response schemas flow through the default handler; caller-supplied handlers continue to own their own response contract.
  • Likert entries must be unique and strictly increasing, and model responses must exactly match a configured integer level.
  • Typed rubric collections are immutable or defensively snapshotted to keep scorer identifiers and runtime behavior stable.
  • First-party consumers and executable docs were migrated, including Crescendo, Tree of Attacks, the fuzzer, fairness benchmark examples, the psychosocial scenario, scorer initializers, and paired Jupytext notebooks.
  • Documentation examples now show the final composition API and synchronized .py / .ipynb representations.

Breaking changes (v1.0)

Legacy path-based constructor arguments and transitional helpers are removed in favor of explicit composition constructors and from_* factories. Notably, from_scale_arguments / load_scale_arguments are replaced by from_scale(...) with NumericRubric; the minimal normalization type is NumericRange. No deprecation shims remain.

Testing

  • Full unit suite: 10,272 passed, 120 skipped
  • Changed-file Ruff formatting/checks, notebook linting, pre-commit hooks, and ty checks pass
  • Six affected executable notebooks were re-run successfully with refreshed outputs
  • The Azure SQL attacks notebook retains its previous output because the retired demo database hostname no longer resolves

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 :))

Comment thread tests/unit/score/test_self_ask_likert.py Outdated
Comment thread pyrit/score/float_scale/self_ask_scale_scorer.py Outdated
Comment thread pyrit/score/float_scale/self_ask_scale_scorer.py Outdated
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
Copilot AI added 7 commits July 10, 2026 14:29
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>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5ae1b829-e7b8-45e7-825b-500377557df1
Render scorer prompts and runtime configuration from shared immutable rubric objects, and validate classifier and Likert responses against those contracts.

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

Copilot-Session: 5ae1b829-e7b8-45e7-825b-500377557df1
Resolve the scorer test conflict against the composition helper and retain the merged Crescendo scorer factory migration.

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

Copilot-Session: 5ae1b829-e7b8-45e7-825b-500377557df1
Refresh paired Jupytext metadata after merging the latest main branch so all changed notebooks remain synchronized.

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

Copilot-Session: 5ae1b829-e7b8-45e7-825b-500377557df1
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5ae1b829-e7b8-45e7-825b-500377557df1
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5ae1b829-e7b8-45e7-825b-500377557df1
@romanlutz romanlutz enabled auto-merge July 12, 2026 03:52
@romanlutz romanlutz changed the title Scorer composition (PR C): roll pure-composition API out to remaining LLM scorers (3/3) Scorer composition (PR C, 3/3): complete LLM rollout with typed rubrics Jul 12, 2026
@romanlutz romanlutz added this pull request to the merge queue Jul 12, 2026
Merged via the queue into microsoft:main with commit 566d4a3 Jul 12, 2026
53 checks passed
@romanlutz romanlutz deleted the romanlutz-scorer-composition-rollout-clean branch July 12, 2026 04:18
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