Skip to content

BUG: include ordered parameters in TemplateSegmentConverter identity - #3905

Merged
Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
Goldloli:fix/template-segment-identity-parameters
Nov 5, 2026
Merged

Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
Goldloli:fix/template-segment-identity-parameters

Conversation

@Goldloli

Copy link
Copy Markdown
Contributor

Fixes #3902

What

TemplateSegmentConverter._build_identifier now includes the ordered prompt_template.parameters list in the identifier params, replacing the bare number_parameters count. 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 with ValueError: Instance 'TemplateSegmentConverter::…' already exists.

Verification

The repro from the issue, on this branch:

hash equal: False
both registered OK

(before the fix: hash equal: True, then ValueError on the second registration)

pytest tests/unit/converter/test_template_segment_converter.py: 12 passed — including the new regression test test_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 TemplateSegmentConverter changes once, because number_parameters is replaced by the full ordered list in the hashed params. Existing persisted identifiers will not match after upgrade.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 03:06

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.

🟢 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

@Goldloli

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@Goldloli

Copy link
Copy Markdown
Contributor Author

The Build latest failure looks transient: the docs link checker got a 504 (Gateway Time-out) for https://github.com/leondz/garak. The link resolves fine now (301 → NVIDIA/garak), and this PR only touches pyrit/converter/template_segment_converter.py + its unit test, so a re-run of that job should go green.

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 5, 2026
Merged via the queue into microsoft:main with commit ec195cc Nov 5, 2026
85 of 88 checks passed
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.

BUG: TemplateSegmentConverter omits ordered parameter bindings from identity

3 participants