Repository navigation
FEAT: Let a tool argument requirement read a nested field by dotted path - #4609
WatchTree-19 wants to merge 3 commits into
Conversation
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.
There was a problem hiding this comment.
🟡 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
| try: | ||
| return split_argument_path(name) | ||
| except ValueError: | ||
| return (name,) |
There was a problem hiding this comment.
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.
| if not (info.context and info.context.get(_PERSISTED_VALIDATION_CONTEXT)): | ||
| split_argument_path(value) |
There was a problem hiding this comment.
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.


Description
Split from #4360, as suggested there: this lets a
ToolArgumentRequirementread a nested field of a tool call's arguments by dotted path, on its own and based on main.recipient.emailreads 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 asrecipient.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.recipient..email, is rejected.MessageToolCallScorer'smatching_versionmoves 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
tests/unit/models/test_argument_paths.py, plus dotted-path cases in the condition, memory model, argument matching andMessageToolCallScorertests. Each was checked by reverting its part of the change.doc/code/scoring/5_tool_call_scorerexplains dotted names (markdown only).