Repository navigation
FEAT: Add prefill technique with native assistant continuation - #3283
Dev3 ^~^ (shashank03-dev) wants to merge 17 commits into
Conversation
|
This is a great implementation of the prefill attack. Requiring supports_prefill natively in TargetRequirements is the right design decision because attempting to adapt or fall back on targets that drop trailing assistant messages would disguise a target limitation as an attack refusal. Scoping request converters strictly to the prepended user objective preserves the exact prompt tokens intended for continuation, and tagging the prefill as a simulated assistant role keeps memory history truthful. The HuggingFaceChatTarget chat template continuation tests cover the mechanics nicely. |
|
Manohar Paturi (@ManoharPaturi) Thank you :) |
|
Dev3 ^~^ (@shashank03-dev) Sorry, I missed an architectural point in my earlier reviews, especially after asking you to make fixes around the new attack class. I should have caught this before approving. On a closer look, I think prefill should be an attack technique built on The capability and target changes are still useful. The part I'd like to change is how we package the behavior. Prefill does not introduce a new conversation algorithm: it prepares a user objective followed by an assistant prefix, then uses the same sending, scoring, retry, and result-handling flow we already have. That is a better fit for the technique/executor split in Here is the direction I suggest:
There is also still an audio-history regression to address in the shared validation change. With I realize this changes the direction after the earlier feedback, and I'm sorry for the extra work. The goal is to keep the useful prefill support while avoiding another attack subclass for behavior that can share our existing execution scaffolding. If there is a constraint in the technique path that I have missed, please point it out so we can address that shared gap explicitly. |
|
Roman Lutz (@romanlutz) Thanks for the detailed guidance. Agreed — I’ll move prefill into a |
|
Roman Lutz (@romanlutz) I’ve addressed your feedback and updated the PR. Could you pls review it when you get a chance? Thanks! |
Roman Lutz (romanlutz)
left a comment
There was a problem hiding this comment.
The technique-based rewrite addresses the architectural feedback, but two regressions remain in the shared code.
|
Roman Lutz (@romanlutz) Fixed both: LiteLLM now allows the audio history its adapter omits, and |
|
Dev3 ^~^ (@shashank03-dev) One more correction to my earlier guidance, sorry. I tried assistant-ending requests against live OpenAI Chat Completions ( Please adjust the capability policy in this PR:
This supersedes the part of my earlier comment that treated hosted chat APIs as unsupported by default. The request-level policy should be consistent across these adapters rather than tied to whether a particular probe gets the answer we hoped for. |
|
Roman Lutz (@romanlutz) Updated the prefill request-support policy as requested, added provider-boundary coverage, and updated both docs. Also resolved the merge conflicts with current main. 31,921 tests pass locally. Could you pls review and approve the CI runs when you get a chance? Thanks! |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c9ab6db0-42e2-4895-b70d-91474933042b
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c9ab6db0-42e2-4895-b70d-91474933042b
There was a problem hiding this comment.
🟡 Changes recommended
The all-turn modality validation rejects historical error, refusal, and reasoning pieces that adapters serialize or omit, breaking otherwise valid follow-up requests.
1 open issue
What changed in this PR
Adds an opt-in prefill technique to PyRIT’s existing PromptSendingAttack workflow, carrying an assistant prefix through seed preparation, execution, and target adapters.
Changes:
- Adds prefill capability declarations and native Hugging Face assistant continuation.
- Preserves prefix handling, converters, scoring, retries, and distinct evaluation identifiers.
- Adds regression coverage and paired documentation examples.
| File | Description |
|---|---|
tests/unit/setup/test_technique_initializer.py |
Includes prefill in expected registrations. |
tests/unit/setup/techniques/test_prefill_technique.py |
Tests prefill execution and adapter payloads. |
tests/unit/prompt_target/test_round_robin_target.py |
Tests matching child prefill capabilities. |
tests/unit/prompt_target/test_discover_target_capabilities.py |
Tests preservation during capability discovery. |
tests/unit/prompt_target/target/test_target_capabilities.py |
Tests defaults, serialization, and overrides. |
tests/unit/prompt_target/target/test_openai_chat_target.py |
Adds audio-history regression coverage. |
tests/unit/prompt_target/target/test_litellm_chat_target.py |
Tests capability derivation and audio history. |
tests/unit/prompt_target/target/test_huggingface_chat_target.py |
Tests assistant-continuation template options. |
tests/unit/executor/attack/single_turn/test_prompt_sending.py |
Checks positional-parameter compatibility. |
tests/unit/executor/attack/core/test_attack_parameters.py |
Tests keyword-only field preservation. |
pyrit/setup/initializers/techniques/extra.py |
Registers the opt-in prefill technique. |
pyrit/scenario/core/attack_technique.py |
Includes continuation mode in identifiers. |
pyrit/scenario/core/attack_technique_factory.py |
Includes continuation mode in factory identifiers. |
pyrit/prompt_target/openai/openai_response_target.py |
Enables prefill request capability by default. |
pyrit/prompt_target/openai/openai_chat_target.py |
Enables prefill and exempts omitted audio history. |
pyrit/prompt_target/litellm_chat_target.py |
Preserves prefill defaults and handles omitted audio. |
pyrit/prompt_target/hugging_face/hugging_face_chat_target.py |
Continues trailing assistant turns. |
pyrit/prompt_target/common/prompt_target.py |
Validates history modalities and preserves prefill defaults. |
pyrit/prompt_target/common/discover_target_capabilities.py |
Preserves declared prefill support during discovery. |
pyrit/prompt_target/azure_ml_chat_target.py |
Enables prefill request capability by default. |
pyrit/models/target/target_capabilities.py |
Defines the prefill capability. |
pyrit/models/seeds/seed_group.py |
Adds optional assistant-prefix extraction. |
pyrit/models/seeds/attack_technique_seed_group.py |
Validates continuation seed configuration. |
pyrit/models/seeds/attack_seed_group.py |
Combines objectives with assistant prefixes. |
pyrit/executor/attack/single_turn/prompt_sending.py |
Keeps request converters off the prefix. |
pyrit/executor/attack/core/attack_parameters.py |
Propagates continuation mode without shifting positional arguments. |
frontend/src/types/index.ts |
Adds the optional prefill capability field. |
doc/references.bib |
Adds two research references. |
doc/code/executor/1_single_turn.py |
Documents prefill configuration and usage. |
doc/code/executor/1_single_turn.ipynb |
Adds the paired notebook example and output. |
doc/bibliography.md |
Includes the new citation keys. |
Review effort: Balanced
|
Dev3 ^~^ (@shashank03-dev) Could we remove Once preparation has selected a Please keep the distinction between the outgoing message and stored history: In the first case, the simulated assistant message is a completed historical reply, not an open prefix. We should not globally treat every assistant-ending history as prefill. Suggested scope:
This would keep the generic attack parameters smaller and make the execution behavior follow the message we are actually sending. If there is a case where the outgoing message does not provide enough information, please point it out so we can account for that without spreading a second representation of the same state through the attack API. |
|
Roman Lutz (@romanlutz) I removed the duplicate flag from AttackParameters and kept the seed opt-in. Execution now uses the outgoing simulated assistant message; tests cover prefix preservation, objective conversion, ordinary history, and unsupported targets. |

Fixes #3270
Adds an opt-in
prefilltechnique built onPromptSendingAttack. The adapter sends the converted user objective followed by an exact assistant prefix; scoring independently determines attack success.AttackParametersargument, preserves its prefix, and requires native prefill, multi-turn, and editable-history support. Ordinary user requests after assistant history still get converted.Tests: 34,686 passed, 28 skipped, 4 xfailed; 96.28% overall coverage; 98% changed-line coverage. Typing, pre-commit, and paired-doc checks pass. Public SQLite-backed regressions cover both request shapes and refusal/reasoning follow-ups; fake provider boundaries verify the exact objective/prefix order independently of the returned answer.