Skip to content

FEAT: Let a tool argument requirement read a nested field by dotted path - #4609

Open
WatchTree-19 wants to merge 3 commits into
microsoft:mainfrom
WatchTree-19:feat/dotted-argument-paths
Open

WatchTree-19 wants to merge 3 commits into
microsoft:mainfrom
WatchTree-19:feat/dotted-argument-paths

Conversation

@WatchTree-19

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

Copy link
Copy Markdown
Contributor

Description

Split from #4360, as suggested there: this lets a ToolArgumentRequirement read a nested field of a tool call's arguments by dotted path, on its own and based on main.

  • A name such as recipient.email reads one exact object key per segment. A missing key, or a value on the way that is not an object, means the field is missing. A top-level key that is exactly the whole name is read first, so a name written when names were plain keys, such as recipient.email, still reads the key it always read. Paths do not index arrays; a value inside an array can still be matched against the array's compact JSON text.
  • New requirements must be valid paths, so a name with an empty segment, such as recipient..email, is rejected.
  • A requirement read from storage keeps the name it was saved with, since any nonempty name was valid before. Stored scores, seed objectives, seed records and planned seed groups all still load.
  • MessageToolCallScorer's matching_version moves to 3, so scores matched under the old meaning are not reused. Trace evidence on main keeps no arguments, so the OTel scorers are unchanged.

Tests and Documentation

  • New tests/unit/models/test_argument_paths.py, plus dotted-path cases in the condition, memory model, argument matching and MessageToolCallScorer tests. Each was checked by reverting its part of the change.
  • doc/code/scoring/5_tool_call_scorer explains dotted names (markdown only).

A ToolArgumentRequirement name can now be a dotted path such as
recipient.email, read one exact object key per segment. A missing key, or
a value on the way that is not an object, means the field is missing, and
paths do not index arrays. New requirements must be valid paths; a
requirement read from storage keeps its name and matches it as one literal
top-level key, so stored scores still load. MessageToolCallScorer's
matching_version moves to 3.

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

Legacy argument names lose their original matching semantics or trigger validation errors when saved seeds are retrieved, breaking compatibility with persisted conditions.

2 open issues
What changed in this PR

Adds dotted-path argument requirements to PyRIT’s tool-call scoring, allowing checks such as recipient.email against nested JSON objects. This is a standalone portion of #4360; OTel scorers remain unchanged.

Changes:

  • Adds object-only path traversal and rejects empty path segments in new requirements.
  • Adds compatibility handling for stored names and bumps MessageToolCallScorer’s matching version to 3.
  • Expands regression tests and documents path behavior in paired documentation files.
File Description
tests/​unit/​score/​test_tool_argument_matching.py Tests nested matching, array exclusion, and legacy malformed names.
tests/​unit/​score/​test_message_tool_call_scorer.py Tests nested scoring and the matching-version bump.
tests/​unit/​models/​test_condition.py Tests path validation and stored-name compatibility.
tests/​unit/​models/​test_argument_paths.py Adds focused path parsing and traversal tests.
tests/​unit/​memory/​test_memory_models.py Tests loading scores containing legacy argument names.
pyrit/​score/​true_false/​message_tool_call_scorer.py Bumps matching version to prevent old-score reuse.
pyrit/​score/​tool_argument_matching.py Uses path traversal when matching arguments.
pyrit/​models/​score/​expectation.py Imports the shared persisted-validation context key.
pyrit/​models/​score/​condition.py Validates new paths and propagates persistence context.
pyrit/​models/​score/​_argument_paths.py Adds path parsing and nested argument lookup.
doc/​code/​scoring/​5_tool_call_scorer.py Adds Markdown explanation of dotted-path behavior.
doc/​code/​scoring/​5_tool_call_scorer.ipynb Mirrors the Markdown documentation addition.

Review effort: Balanced

Comment thread pyrit/models/score/_argument_paths.py Outdated
Comment on lines +47 to +50
try:
return split_argument_path(name)
except ValueError:
return (name,)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. A top-level key that is exactly the whole name is now read before the path, so a requirement saved as recipient.email still reads that key whenever the call has it. The literal recipient.email test now expects a match, and a new case covers a call with both, where the literal key wins. What remains for an old requirement is that a call carrying only the nested field now matches too, which is the change matching_version 3 marks. In b439055.

Comment on lines +215 to +216
if not (info.context and info.context.get(_PERSISTED_VALIDATION_CONTEXT)):
split_argument_path(value)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks. Stored seed conditions now load with the same persisted context as stored scores, through a new validate_persisted_conditions, in SeedEntry.get_seed, SeedEntry.get_seed_record and planned seed groups, so a condition saved with a name such as a..b loads as it was saved. New tests cover all three and fail without the fix. In b439055.

…ed seeds with them

A top-level argument key that is exactly the whole name is now read before the dotted path,
so a requirement written when names were plain keys, such as recipient.email, still reads the
key it always read. A name that is not a valid path and is not a key is missing.

Stored seed conditions now load with the persisted validation context, in
SeedEntry.get_seed, SeedEntry.get_seed_record and planned seed groups, so a requirement saved
with a name such as a..b loads as it was saved instead of raising.

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.

2 participants