#8677·opik

`scoring_key_mapping` can bind stored data to the reserved `task_span` key

Author: feiiiiii5Created Oct 1, 2026Updated Oct 1, 2026

scoring_key_mapping can bind ordinary stored data to the reserved task_span key, so re-scoring silently passes that data as the task span instead of reporting the missing span.

create_scoring_inputs merges the caller's mapping into the scoring inputs, and nothing stops a mapping from naming a reserved argument — scoring_key_mapping={"task_span": "raw"} puts a dataset item's field under the reserved key.

_compute_metric_scores then reads that key first and hands it to ScorerWrapperMetric.score as the span, before the missing-argument check can run:

python
if (task_span := mapped_scoring_inputs.get(EVALUATION_SPAN_PARAMETER_NAME)) is not None:
    result = metric.score(..., task_span=task_span)

A metric that requires task_span therefore receives the mapped value and scores against it instead of raising ScoreMethodMissingArguments. Re-scoring is exactly where nothing binds a real span, so this is the path where the mistake is invisible: nothing in the result distinguishes a mapped dictionary from a real span.

Impact

The score that comes back is computed from data that is not a span, and the trace shows a normal verdict. This is the failure the rescoring path was hardened against elsewhere: scoring_key_mapping already warns when a mapping matches nothing (arguments_helpers.py:136) because "the metric silently scores the wrong thing". The reserved task_span key is the same problem with a worse outcome, since a wrong span is trusted as a span.

Suggested direction

Two options, and they differ for callers who already have such a mapping:

  1. Reject task_span in scoring_key_mapping — raise, or warn and drop it — since the engine binds the span itself. Simplest to reason about; breaks a mapping that today "works" for a metric with a defaulted task_span.
  2. Ignore mapped task_span during re-scoring (can_bind_task_span=False), so the key never reaches a metric and the missing-argument report applies. No user-facing break, but a mapping that names task_span then silently does nothing.

I lean towards 1, because a mapping that can shadow an engine-bound argument is a footgun regardless of the path, and the existing warning already lists the available keys. Please say which you prefer and I will open a PR.

Note: this is not the same root cause as the task-span rescoring work in #8396 — there, a required task_span is correctly reported; here the value that reaches the metric is not a span at all.

Reproduction
python
from opik.evaluation.metrics import arguments_helpers

mapped = arguments_helpers.create_scoring_inputs(
    dataset_item={"raw": {"totally": "not a span"}},
    task_output={"out": 1},
    scoring_key_mapping={"task_span": "raw"},
)
assert "task_span" in mapped and mapped["task_span"] == {"totally": "not a span"}

Run against main (2438f12fe2), SDK only, no backend:

  • create_scoring_inputs returns the key with the dataset item's value — no warning, no error.
  • The engine's task_span := mapped_scoring_inputs.get("task_span") branch is taken, so ScorerWrapperMetric.score binds task_span=<that dict> and the required-span scorer runs instead of reporting a missing argument.