Repository navigation
FEAT: Match tool argument requirements from OTel trace arguments - #4359
Open
WatchTree-19 wants to merge 9 commits into
Open
WatchTree-19 wants to merge 9 commits into
WatchTree-19 wants to merge 9 commits into
Conversation
… 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.
Contributor
There was a problem hiding this comment.
🟡 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.
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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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:
OtelTraceSourcenow stores each call's parsed arguments, consistent withOtelExecutionTraceSourceand storedfunction_callpieces, andOtelToolCallScorermatches them with #4150's unchanged matcher.Behavior change: trace arguments are now stored and matched.
gen_ai.tool.call.argumentsattribute (the GenAI semantic convention attribute for tool call arguments) and stores the parsed JSON object onToolExecution.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_retainedbecomes a strict boolean marker. The source writesTrue. A payload markedFalsecannot hold arguments.schema_versionstays 1, so stored payloads still load.normalization_version: 2, so the behavior change shows in source identity.arguments_retainedisFalse), 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:send_emailto == a{"to": "a", ...}to == a{"to": "b", ...}to == atoto == a,body == x{"to": "a", "body": "x"}to == a,body == x{"to": "a", "body": "y"}body == x, pluslookupby namelookupcalllookupbeing 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 as1e400) 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.
MessageToolCallScoreris unchanged: storedfunction_callpieces hold the full arguments, and it still never reports false.OtelToolCallOrderScorerkeeps its verdicts and still does not match arguments; its rationale and warning now say that it does not match tool arguments and point toOtelToolCallScorerorMessageToolCallScorer, instead of saying trace evidence does not retain arguments.Tests and Documentation
tests/unit/score/test_tool_argument_matching.pyandpyrit/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 recordsnormalization_version2.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.pyandtests/unit/models/test_trace.py: round trips with retained arguments, the stored form without them, rejection of a coerced marker, rejection of arguments whenarguments_retainedis false, unstructured arguments.doc/code/scoring/5_tool_call_scorer.pyand.ipynb: how trace arguments are stored and how argument requirements are scored from traces, kept in sync.How it was tested
ruff checkandruff format --checkclean.tyreports no diagnostics on the changed source files..ipynbcells were regenerated from the.pycells and checked to match them, with outputs untouched. The notebook was not re-executed.