Skip to content

FEAT Add adaptive jailbreaking #266

Open

Description

@romanlutz

Is your feature request related to a problem? Please describe.

The technique from this repo is not captured in PyRIT yet https://github.com/tml-epfl/llm-adaptive-attacks

Describe the solution you'd like

Investigate the best way to integrate, e.g., as an attack, and propose a high-level plan here. Then, maintainers will provide feedback and help with questions during the implementation phase.

Describe alternatives you've considered, if relevant

Additional context

Activity

  1. added
    enhancement
    help wanted
    on Jun 28, 2024
  2. donebydan commented on Sep 16, 2024

    @donebydan

    I'd be keen to explore this Open Issue! 🙏

  3. changed the title [-]Add adaptive jailbreaking[/-] [+]FEAT Add adaptive jailbreaking[/+] on Nov 13, 2024
  4. romanlutz commented on Dec 8, 2025

    @romanlutz
    ContributorAuthor

    Looks like endpoints and the corresponding APIs don't provide logprobs anymore nowadays so I think we can pretty much close this. Wdyt Dan Jones (@donebydan)?

  5. donebydan commented on Dec 8, 2025

    @donebydan

    Happy to close. I don't have permission to do so - could you? 🙏

  6. romanlutz commented on Dec 11, 2025

    @romanlutz
    ContributorAuthor

    Actually, I found a couple models that still do provide logprobs according to the documentation so maybe still worth doing? We would need someone to investigate a bit on this.

  7. immu4989 commented on May 24, 2026

    @immu4989
    Contributor

    Roman Lutz (@romanlutz) — taking up the investigation request. Quick survey of logprob exposure across mainstream APIs and open-model serving as of today, plus the relevant PyRIT integration points.

    Logprob availability (2026)

    Provider Logprobs? Notes
    OpenAI Chat Completions Yes logprobs: true + top_logprobs (1–20) on standard chat models
    Anthropic Messages API No No logprobs parameter; usage only carries token counts (docs)
    Google Gemini generateContent No No logprobs / responseLogprobs parameter in the current API reference
    Self-served open models (vLLM, TGI, llama.cpp) Yes Native; top-k logprobs configurable per-request
    Aggregated open-model APIs (Together, Fireworks, OpenRouter) Yes for most Pass-through to vLLM/TGI under the hood

    Implication for the Andriushchenko-style attack

    The technique requires logprob feedback for suffix optimization, so it's no longer universal — but coverage is still meaningful: works against OpenAI's main chat models and against any open model served via vLLM/TGI (locally hosted Llama, Qwen, Mistral, etc. — exactly the targets red-teamers most need to evaluate). It's a partial-coverage attack now, not an all-targets attack.

    Relevant PyRIT integration points

    A few things I noticed reading the current code:

    1. PromptChatTarget is deprecated in v0.14.0 in favor of PromptTarget + TargetConfiguration capabilities (per pyrit/prompt_target/common/prompt_chat_target.py). New work should target the PromptTarget interface.
    2. Neither openai_chat_target.py nor openai_completion_target.py currently passes logprobs=True or processes logprob arrays — target-side opt-in would be needed.
    3. MessagePiece.prompt_metadata is typed dict[str, Union[str, int]] — too restrictive for logprob arrays. Integration would need either a new field on MessagePiece (e.g., response_logprobs), or a separate carrier model.

    One question before going further

    Given the partial coverage, is the team open to landing this as an attack class that's explicit about target compatibility — checks for a supports_logprobs capability on the target and raises clearly when not supported — rather than requiring universal support?

    If yes, I'd be happy to put up a small spike: minimal target-side opt-in (return_logprobs on OpenAIChatTarget), the MessagePiece extension to carry the data, and a stub attack that consumes it. ~200–300 LOC, additive, easy to review — with credit to Dan Jones (@donebydan)'s [DRAFT] PR #537 where applicable. The Andriushchenko adaptive search itself would be a follow-up once the plumbing is in place.

    If the team would rather close this as "not viable enough to warrant the plumbing," also a clean answer — happy to file the closing rationale as a comment for future readers.

  8. romanlutz commented on Jun 3, 2026

    @romanlutz
    ContributorAuthor

    We have TargetCapabilities now so this would just be one more! I can assign the item to you.

  9. romanlutz commented on Jun 3, 2026

    @romanlutz
    ContributorAuthor

    Actually Imran Ahamed (@immu4989) has the first right to pick it up I suppose 🙂 I think it's still relevant for targets that expose the logprobs.

  10. immu4989 commented on Jun 3, 2026

    @immu4989
    Contributor

    Thanks Roman Lutz (@romanlutz), I will work on it.
    @sajisanchu1913-source appreciate the courtesy.

  11. immu4989 commented on Jun 7, 2026

    @immu4989
    Contributor

    What this proposes

    Implement the adaptive jailbreaking attack from Andriushchenko et al. 2024 (arXiv:2404.02151, tml-epfl/llm-adaptive-attacks) as a PyRIT single-turn attack strategy. Gate it on a new TargetCapabilities flag that advertises logprob support, so the attack cleanly skips targets that do not expose token-level probabilities (Anthropic, Gemini) and runs against the ones that do (OpenAI Chat Completions with logprobs=True, vLLM, TGI, Together, Fireworks, OpenRouter).

    Why

    The technique searches over token-level insertions and suffix completions, ranking candidate jailbreak prompts by the target model's logprob assigned to a chosen affirmative continuation. It is the canonical "white-box-ish via logprobs" attack and complements the gradient-based GCG already in pyrit/auxiliary_attacks/gcg/ (GCG needs full white-box; adaptive attacks need only the top-N logprobs that hosted APIs expose). PyRIT users running broad red-team sweeps can include this against any provider that exposes logprobs, without needing local weights.

    This issue was on the verge of being closed in 2025-12 when logprobs were thought to be uniformly retired, but my prior investigation in this thread confirmed they are still available on OpenAI Chat Completions, vLLM, TGI, Together, Fireworks, and OpenRouter as of 2026-05. Targeting the subset of capable endpoints via TargetCapabilities makes the issue tractable today.

    Proposed architecture

    Three small additions, each with clear seams.

    1. New capability flag

    In pyrit/prompt_target/common/target_capabilities.py, add to CapabilityName:

    LOGPROBS = "supports_logprobs"

    OpenAIChatTarget advertises it (and respects the new logprobs=True, top_logprobs=N request params). Other targets default to absent. The attack uses the standard TargetCapabilities.requires(...) check, so it raises a clear error against an incompatible target.

    2. Logprob carrier on the response

    The attack needs per-token logprobs from the assistant message. Today nothing in PyRIT carries them. Two viable options for the design discussion (open question below), but the proposal is to add a typed logprobs: Optional[list[TokenLogprob]] field on MessagePiece where TokenLogprob is a small dataclass holding the token string, its logprob, and the top-N alternatives. prompt_metadata is currently typed dict[str, str | int | float] which is too narrow.

    3. Attack strategy

    New file pyrit/executor/attack/single_turn/adaptive_jailbreak.py containing AdaptiveJailbreakAttack(SingleTurnAttackStrategy). Modeled on the size and shape of skeleton_key.py (185 lines) and flip_attack.py (107 lines), not the larger orchestrators. Constructor accepts objective_target, the search budget (max_iterations), the affirmative continuation template, an optional adversarial-suffix seed, and a stopping criterion. The strategy registers CapabilityName.LOGPROBS as a required capability so PyRIT's existing target-compatibility check enforces it.

    Scope: variants in v1 vs deferred

    The paper has three main components. Proposed split:

    • In v1 (this PR): Random search over token insertions, with logprob-driven candidate ranking. This is the technique's core and produces the headline numbers in the paper.
    • In v1 (this PR): Adversarial suffix optimization, paired with the affirmative-continuation template. Same scoring path as variant 1.
    • Deferred to a follow-on issue/PR: Self-transfer (cross-model prompt reuse). It adds another orchestrator-level wiring (carrying a successful prompt across targets) and is independently testable; keeping it out of v1 keeps the PR focused.

    Open design questions

    Need Roman Lutz (@romanlutz) steer before coding:

    1. Where do logprobs live on the response. Proposal above: a new typed MessagePiece.logprobs field with a TokenLogprob dataclass. Alternative: relax prompt_metadata to allow nested lists and put logprobs there. The typed field is cleaner but is a wider change. Which would you prefer?
    2. Capability semantics. LOGPROBS advertises "this target can return logprobs if asked." Should we also encode the top_logprobs cap (OpenAI is 20, some are lower)? Easiest is a separate max_top_logprobs: int = 0 field on the capability descriptor that is only meaningful when LOGPROBS is set.
    3. Unsupported-capability behavior. Default to RAISE so a user pointing the attack at Anthropic gets a clear error immediately, rather than silently running a degraded version. Confirm?
    4. GCG sibling placement. GCG lives under pyrit/auxiliary_attacks/, separate from the modern pyrit/executor/attack/ tree. Adaptive jailbreaking is a closer fit for executor/attack/single_turn/ because it works against hosted models without local weights. Confirm that is the right home.
    5. Test fixtures. Real logprob captures from a hosted endpoint cost API calls and are not reproducible in CI. Plan: mock the chat target with deterministic logprob arrays, plus a small offline fixture file with a recorded response shape so the parser path is exercised against real data once.

    Implementation plan

    • This PR (v1): capability flag, OpenAIChatTarget logprob plumbing, MessagePiece carrier, AdaptiveJailbreakAttack with random-search and suffix-optimization variants, unit tests with mocked logprobs, one notebook in doc/code/executor/attack/ showing usage against OpenAIChatTarget pointed at OpenAI or a vLLM-serving endpoint.
    • Follow-on PR (separate issue): self-transfer variant. Adds an orchestrator step that carries a successful jailbreak prompt across multiple AdaptiveJailbreakAttack runs against different targets.
    • Out of scope: logprob plumbing on non-OpenAI hosted targets (Together, Fireworks, OpenRouter, vLLM HTTP). They use the same OpenAI-compatible interface, so they inherit OpenAIChatTarget's logprob support transparently, but I will not write per-provider integration tests in this PR.

    References

    • Andriushchenko, Croce, Flammarion, Jailbreaking Leading Safety-Aligned LLMs with Simple Adaptive Attacks, arXiv:2404.02151 (2024), reference implementation at https://github.com/tml-epfl/llm-adaptive-attacks
    • Prior thread investigation in this issue (logprob availability sweep across providers, 2026-05-24)
  12. immu4989 commented on Jun 26, 2026

    @immu4989
    Contributor

    Bumping this. Happy to start coding once you can weigh in on the design questions above, especially Q1 (where logprobs live on the response) and Q3 (RAISE vs ADAPT for unsupported targets). If a different direction works better, also fine to redirect.

  13. romanlutz commented on Nov 11, 2026

    @romanlutz
    ContributorAuthor

    Sorry for the slow reply Imran Ahamed (@immu4989) we've been flooded with issues and PRs 😆 The overall plan makes sense. Answers below, with one caveat: the proposal is from June and the codebase has moved quite a bit since (including a change merged just now that affects Q1/Q2), so expect some drift from the file paths you referenced.

    Q1 (where logprobs live): Since you wrote this, #3506 landed, which added runtime generation configuration. Please follow that pattern rather than adding a new field to MessagePiece:

    • Request side: add logprobs/top_logprobs fields to RequestGenerationConfig (pyrit/models/target/request_generation_config.py), mapped to the new capability via FIELD_CAPABILITIES the same way temperature maps to CapabilityName.TEMPERATURE.
    • Response side: a small typed pydantic model (your TokenLogprob idea) serialized into prompt_metadata under its own key, following the RequestGenerationInfo precedent. prompt_metadata is dict[str, Any] now, so no schema change is needed, and the typed model keeps it from becoming a loose dict.

    Q2 (encoding the top-N cap): No — that varies a lot by provider/model and would go stale quickly. Keep the capability a boolean and let the provider's own error surface if a request asks for more than the endpoint supports.

    Q3 (unsupported behavior): Yes, RAISE. Logprobs can't be adapted around, and non-adaptable capabilities always raise in the current design (CapabilityHandlingPolicy), so this is consistent.

    Q4 (placement): pyrit/auxiliary_attacks/ is gone; GCG now lives under pyrit/executor/promptgen/gcg, and the Fuzzer is under promptgen as well. This attack is the same shape as both — an iterative search loop that generates candidate prompts, queries the target, and scores the candidates (here by logprob of the affirmative continuation) — so executor/promptgen is the right home, not executor/attack/single_turn. The optimized prompt can then be sent/validated via PromptSendingAttack like we do for GCG suffixes.

    Q5 (tests): Yes — unit tests with mocked logprob payloads plus the recorded response fixture sounds right. We also typically have integration tests for real targets and end-to-end tests for full scenarios, so plan on at least an integration test against a real logprob-capable endpoint.

    Looking forward to the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementhelp wanted

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions