← Back to Pull requests

feat: support overridable default grader models #6678

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 20, 2026 04:13 UTC
Author

Problem or current behavior

Evaluation authors need to provide a default grader while allowing runners to replace it with another model or a panel. Today, preserving both the fallback and supporting a panel of grader models passed via model_roles requires a wrapper around the built-in scorer:

@scorer(metrics=[accuracy(), stderr()])
def grader():
    async def score(state, target):
        model = None if "grader" in model_roles() else "openai/gpt-4.1"
        return await model_graded_qa(model=model)(state, target)

    return score

The shorter alternatives have different behavior:

  • Passing model="openai/gpt-4.1" overrides the runner's grader role.

  • Passing get_model(role="grader", default=...) selects only the first model of a bound panel, bypassing the built-in scorer's panel reduction.

  • Setting Task(model_roles={"grader": "openai/gpt-4.1"}) constructs the default provider when the task is constructed. A runner intending to use another provider can encounter a missing OpenAI/Anthropic SDK or credential error before its override is applied.
  • This follows the downstream problem documented in inspect_evals #2867: resolving the grader role before a built-in scorer collapses a bound panel.

    Result or new behavior

    The same default grader can be declared directly:

    grader = model_graded_qa(
        model_role=ModelRole("grader", default="openai/gpt-4.1"),
    )
    

    Both model_graded_qa() and model_graded_fact() resolve this default at scoring time, only when the role is unbound. A runner can supply a single grader or a complete panel without installing or configuring the unused default provider. The scorer retains its existing reducer and resolves the role again when reused in another evaluation context.

    For a default with generation settings, a base URL or provider arguments, default also accepts ModelConfig:

    ModelRole(
        "grader",
        default=ModelConfig(
            model="openai/gpt-4.1",
            config=GenerateConfig(temperature=0, max_tokens=1024),
        ),
    )
    

    Those settings apply to the fallback only. Runner-supplied graders keep their own settings. An unavailable default provider raises its normal error when that default is needed.

    Both built-in scorers use the standard @scorer decorator. Dictionary role specifications are normalized for logging during registry argument capture, so they use ModelRole's credential filtering without changing the factory's runtime arguments. Conversion recognizes resolved ModelRole annotations, optionally combined with str or None; unrelated dictionaries and string annotations keep their existing behavior.

    Compatibility and migration

    No migration required. Existing model= precedence, role bindings, panel reducers and behavior without a default remain unchanged. get_model() and task-level role binding are unchanged.

    The new field is stored in scorer options so saved logs can reconstruct the grader. Existing roles without defaults retain their serialized shape; reconstructing scorers that use the new field requires a version supporting it. Configured defaults filter API keys, aws_* arguments and iterators using the existing model-log policy. Runtime credentials remain available to the provider, while rescoring obtains credentials from its runtime environment. Built-in scorer dictionary specifications receive the same filtering during registry argument capture as ModelRole objects.

    Draft API choice: required=True cannot be combined with a default, preserving ModelRole.required's documented requirement for a role binding. get_model() currently permits that combination, so matching its convention is an alternative for review. Defaults accept model names or ModelConfig; constructed models and default panels are outside this change's scope.

    Validation

    The regression test simulates an unavailable OpenAI SDK. Eager task-role defaults raise the dependency error; both built-in scorers with deferred defaults still grade using scalar or panel overrides, and raise only when the OpenAI default is needed. Tests also exercise saved-log rescoring, configuration isolation and credential filtering through keyword, positional and reconstructed scorer inputs.

  • Python 3.12.10 with the locked development dependencies: uv run --no-sync make check passes.

  • uv run --no-sync pytest tests/util/test_registry.py tests/scorer tests/model/test_model_roles.py tests/_eval/test_score.py -q --tb=short --color=no: 1,137 passed, 312 gated cases skipped. The added registry cases check argument preservation, unrelated dictionary unions and file-defined factories with postponed annotations.

  • The full-suite run (PYTEST_ADDOPTS='-n 8 --tb=short --color=no --maxfail=1' uv run --no-sync make test) stopped with 23,186 passed, 12,593 skipped and two terminal-display failures: tests/sentinel/test_sentinel_human.py::test_no_call_can_hide_or_pass_for_another and tests/test_eval.py::test_display_type_change_inside_screen_keeps_terminal_cleanup[plain]. Both reproduce on a clean checkout of upstream base 8012060c0 with the same environment. The baseline probes failed all three selected sentinel variants and the display-cleanup case. The local full suite is not reported as passing.
  • Slow tests

  • Trio, Python 3.12.10: uv run --no-sync pytest tests/scorer/test_model_graded.py --runtrio -q --tb=short --color=no: 18 passed, 282 skipped because this invocation selects only Trio variants.

  • Not run: live-provider tests. Provider implementations are unchanged; the new behavior is tested with mock models and blocked SDK imports, without provider calls.
  • Agent review

    Authored with Codex. Two fresh-context reviews by separate Codex agents (GPT-6 family; exact variant unavailable), each followed by verification in the reviewer's existing context.

  • The first review found that dictionary role specifications could bypass credential filtering. Both built-ins now filter these inputs during registry argument capture, with regression coverage for keyword, positional and reconstructed scorer inputs. It also corrected argument passing in the scorer-spec regression.

  • The second review checked the refactor to standard @scorer decorators. It found three compatibility regressions in the initial annotation handling: file-defined factories absent from sys.modules, unrelated postponed annotations, and unions accepting ordinary dictionaries. Removing string-annotation resolution and restricting conversion to unambiguous role types addressed all three, with regression coverage. Follow-up review found no remaining issues.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: tonydzi Review duration: 19565m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.57) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #6678"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%