Skip to content

FEAT: Match tool argument requirements from OTel trace arguments - #4359

Open
WatchTree-19 wants to merge 9 commits into
microsoft:mainfrom
WatchTree-19:feat/redacted-argument-matching
Open

WatchTree-19 wants to merge 9 commits into
microsoft:mainfrom
WatchTree-19:feat/redacted-argument-matching

Conversation

@WatchTree-19

@WatchTree-19 WatchTree-19 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

This started from open question 2 in the scorer contract design: "How is a redacted argument matched?" It leaves redaction open for a separate proposal. It builds on argument matching (#4150).

Since #4150, trace evidence keeps no arguments at all, so an argument requirement scored from traces is always undetermined. This PR takes the smallest step that lets traces decide argument requirements: OtelTraceSource now stores each call's parsed arguments, consistent with OtelExecutionTraceSource and stored function_call pieces, and OtelToolCallScorer matches them with #4150's unchanged matcher.

Behavior change: trace arguments are now stored and matched.

  • The source reads each span's gen_ai.tool.call.arguments attribute (the GenAI semantic convention attribute for tool call arguments) and stores the parsed JSON object on ToolExecution.arguments. The raw attribute is not stored. There is no option and no allowlist; write-time redaction is not part of this PR.
  • ToolEventsObservationPayload.arguments_retained becomes a strict boolean marker. The source writes True. A payload marked False cannot hold arguments. schema_version stays 1, so stored payloads still load.
  • The source identity records normalization_version: 2, so the behavior change shows in source identity.
  • Observations stored before this change hold no arguments (arguments_retained is False), so an argument requirement replayed on them stays undetermined, with the rationale and warning main gives today.

How a call is matched. A call's stored arguments decide the requirement as they do for MessageToolCallScorer. Concretely, with complete evidence:

Requirement on send_email Call arguments Verdict
to == a {"to": "a", ...} true
to == a {"to": "b", ...} false
to == a no to false
to == a, body == x {"to": "a", "body": "x"} true
to == a, body == x {"to": "a", "body": "y"} false
body == x, plus lookup by name no lookup call false (rests on lookup being absent)

Arguments that are missing from the span, do not parse, are not a JSON object, or hold a non-finite number (NaN, Infinity, or a literal too large to represent, such as 1e400) leave the call undetermined, and the rationale says the arguments could not be read.

Write-time redaction is not added here. Any write-time redaction would be a separate proposal tied to a named operator need (see #4277's closure). Stacked #4360 should rebase on this and drop its kept-path allowlist. MessageToolCallScorer is unchanged: stored function_call pieces hold the full arguments, and it still never reports false. OtelToolCallOrderScorer keeps its verdicts and still does not match arguments; its rationale and warning now say that it does not match tool arguments and point to OtelToolCallScorer or MessageToolCallScorer, instead of saying trace evidence does not retain arguments.

Tests and Documentation

  • tests/unit/score/test_tool_argument_matching.py and pyrit/score/tool_argument_matching.py: unchanged from main.
  • tests/unit/score/test_otel_tool_call_scorer.py: the source stores the parsed arguments and not the raw attribute, unreadable or non-finite arguments are not retained and stay undetermined, the verdict table above through scoring and replay, older name-only observations replay undetermined with main's rationale and warning, the source identity records normalization_version 2.
  • tests/unit/score/test_otel_tool_call_order_scorer.py: an argument requirement on the order scorer stays undetermined, with the rationale and warning saying it does not match tool arguments.
  • tests/unit/models/test_tool_observation.py and tests/unit/models/test_trace.py: round trips with retained arguments, the stored form without them, rejection of a coerced marker, rejection of arguments when arguments_retained is false, unstructured arguments.
  • doc/code/scoring/5_tool_call_scorer.py and .ipynb: how trace arguments are stored and how argument requirements are scored from traces, kept in sync.

How it was tested

python -m pytest -q -n 4 tests/unit/score tests/unit/models tests/unit/registry/test_source_registry.py tests/unit/executor/attack/test_seed_expectation_transport.py tests/unit/prompt_target/target/test_litellm_chat_target.py
python -m pytest -q tests/unit/score/test_otel_tool_call_order_scorer.py tests/unit/score/test_otel_tool_call_scorer.py tests/unit/models/test_tool_observation.py tests/unit/models/test_trace.py tests/unit/score/test_tool_argument_matching.py tests/unit/common/test_lazy_package_imports.py
python -m ruff check <changed files>
python -m ruff format --check <changed files>
ty check <changed source files>
  • The suites that use these contracts: 11236 passed, 4 skipped. The focused files, the order scorer tests and the lazy import test: 524 passed.
  • ruff check and ruff format --check clean. ty reports no diagnostics on the changed source files.
  • The doc change is Markdown only: the .ipynb cells were regenerated from the .py cells and checked to match them, with outputs untouched. The notebook was not re-executed.

… score

OtelTraceSource gains kept_arguments, an opt-in list of top-level argument
names. It reads each span's gen_ai.tool.call.arguments attribute, keeps the
named arguments on ToolExecution.arguments, and drops the rest, and the raw
attribute, before the observation is stored. The payload records the list, and
its validator rejects an event that holds any other argument.

An argument the source did not keep was redacted at write time. A requirement
on it can neither confirm nor refute a call, so a verdict that would rest on it
is undetermined even when the trace evidence is complete, and the rationale
names the arguments that were not kept, or, when the source keeps none, says
that trace evidence keeps no arguments. A kept argument that the call lacks, or
whose value does not match, still refutes the call, and so does complete
evidence with no call of the tool. Arguments that are missing, do not parse, or
are not a JSON object leave the call undetermined.

With no kept arguments, the source identity, the payload and each event keep
their stored form.
Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:04

Copilot AI left a comment

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.

🟡 Changes recommended

Non-finite numbers can bypass argument validation through numeric overflow or dictionary inputs, allowing confident verdicts when unreadable evidence should remain undetermined.

1 open issue
What changed in this PR

This PR extends tool argument matching from #4150 with opt-in argument retention for trace evidence. It treats redacted arguments as unknown while preserving confident verdicts supported by retained arguments or tool-name coverage.

Changes:

  • Adds argument retention settings and payload validation while preserving default serialization.
  • Updates trace scoring and rationales to account for redacted arguments.
  • Adds retention, matching, and replay tests, plus synchronized documentation.
File Description
tests/​unit/​score/​test_tool_argument_matching.py Tests redacted versus absent arguments.
tests/​unit/​score/​test_otel_tool_call_scorer.py Tests retention, scoring, replay, and source identity.
tests/​unit/​models/​test_trace.py Tests argument serialization and validation.
tests/​unit/​models/​test_tool_observation.py Tests retention declarations and payload compatibility.
pyrit/​score/​true_false/​otel_tool_call_scorer.py Uses retained arguments and explains redaction.
pyrit/​score/​tool_argument_matching.py Treats redacted arguments as unknown.
pyrit/​score/​observation/​otel_trace_source.py Adds opt-in argument parsing and retention.
pyrit/​models/​score/​trace.py Adds optional retained arguments to execution evidence.
pyrit/​models/​score/​observation.py Records and validates retained argument names.
doc/​code/​scoring/​5_tool_call_scorer.py Documents trace argument retention and scoring.
doc/​code/​scoring/​5_tool_call_scorer.ipynb Mirrors the documentation changes in notebook Markdown.

Review effort: Balanced

Comment on lines +56 to +58
if not isinstance(value, dict):
return None
return {name: value[name] for name in kept if name in value}
A literal too large to represent, such as 1e400, parses to infinity, and an
already-parsed arguments object skips parsing altogether, so both reached the
matcher. The source now rejects any NaN or infinite number, nested ones
included, on both paths, and the call stays undetermined.
WatchTree-19 and others added 5 commits November 24, 2026 23:03
ty now reports assigning the Any from json.loads to a JsonValue as unsound, so the parsed
arguments are cast to JsonValue, as the other readers of stored JSON do.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
OtelTraceSource now stores the parsed gen_ai.tool.call.arguments object on
each tool event (missing, unparseable, non-object, or non-finite values stay
None) and records normalization_version 2. The kept_arguments allowlist and
redaction path are removed, match_tool_arguments is restored to main, and
ToolEventsObservationPayload.arguments_retained becomes a strict bool marker
(false payloads hold no arguments), keeping schema_version 1 so stored
name-only observations still load and replay undetermined.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Trace evidence now retains arguments, so OtelToolCallOrderScorer no longer
says it does not. It keeps its verdicts and says instead that it does not
match tool arguments, pointing to OtelToolCallScorer or MessageToolCallScorer.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@richlundeen Richard Lundeen (richlundeen) changed the title FEAT: redacted argument matching, so a redacted value never decides a score FEAT: Match tool argument requirements from OTel trace arguments Nov 25, 2026

This branch has not been deployed

No deployments
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