Repository navigation
BUG: include ordered parameters in TemplateSegmentConverter identity - #3905
Merged
Roman Lutz (romanlutz) merged 4 commits intoNov 5, 2026
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the change that distinguishes converter identities by parameter binding order.
No open issues 🎉
What changed in this PR
Fixes #3902 by making TemplateSegmentConverter identity reflect parameter binding order, allowing differently ordered configurations to coexist under automatic registry names.
Changes:
- Replaces the parameter count in identifier data with the ordered parameter names.
- Adds a regression test verifying that reversed parameter orders produce distinct hashes.
- Changes existing converter hashes once on upgrade, as noted in the PR description.
| File | Description |
|---|---|
tests/unit/converter/test_template_segment_converter.py |
Adds regression coverage for parameter-order identity. |
pyrit/converter/template_segment_converter.py |
Includes ordered parameter names in the identifier. |
Review effort: Balanced
Contributor
Author
|
@microsoft-github-policy-service agree |
This was referenced Nov 5, 2026
Roman Lutz (romanlutz)
approved these changes
Nov 5, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
Author
|
The |
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.
Fixes #3902
What
TemplateSegmentConverter._build_identifiernow includes the orderedprompt_template.parameterslist in the identifier params, replacing the barenumber_parameterscount. Two converters sharing a template text but binding parameters in different orders now produce distinct hashes and can be registered under automatic default names simultaneously.The parameter count was redundant once the ordered list is part of the identity, so it is replaced rather than kept alongside.
Why
The ordered parameters list controls which prompt segment fills which template parameter in
convert_async(dict(zip(parameters, segments))), so["left", "right"]and["right", "left"]render differently. The identity previously captured only the template text hash, the parameter count, and the seed, so both orderings hashed identically and the second automatic registration failed withValueError: Instance 'TemplateSegmentConverter::…' already exists.Verification
The repro from the issue, on this branch:
(before the fix:
hash equal: True, thenValueErroron the second registration)pytest tests/unit/converter/test_template_segment_converter.py: 12 passed — including the new regression testtest_template_segment_converter_identity_includes_parameter_order, which fails on the unpatched source (verified by stashing the fix) and passes with it.Note: the identifier hash for every existing
TemplateSegmentConverterchanges once, becausenumber_parametersis replaced by the full ordered list in the hashed params. Existing persisted identifiers will not match after upgrade.