Skip to content

FEAT Beam search #949

Open
Open

Description

@romanlutz

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

The following blog describes an interesting attack technique of randomly appending tokens to evade detection. We should explore if it works well and consider adding to PyRIT.

https://security.googleblog.com/2025/01/how-we-estimate-risk-from-prompt.html

Activity

  1. added
    enhancement
    help wanted
    on Jun 7, 2025
  2. adrian-gavrila commented on Aug 4, 2025

    @adrian-gavrila
    Contributor

    Sounds interesting, I'd like to give this a shot if others aren't already working on this issue.

  3. romanlutz commented on Aug 5, 2025

    @romanlutz
    ContributorAuthor

    Please do! Nobody is on it to the best of my knowledge.

  4. added
    not ready yet
    and removed
    help wanted
    on Sep 22, 2026
  5. romanlutz commented on Sep 22, 2026

    @romanlutz
    ContributorAuthor

    Prior implementation work:

    I'm marking this not ready yet and unassigning Adrian Gavrila (@adrian-gavrila). Before another implementation starts, we need to resolve the design and correctness issues identified in #1346, especially:

    • keeping execution state and conversation IDs isolated per beam/objective;
    • preserving caller target settings, including store=False;
    • preferring a beam that actually reaches the objective instead of selecting only by an auxiliary score;
    • clearing or removing failed beams so stale state cannot win;
    • making identifiers and scoring configuration capture behavior-defining settings;
    • continuing from original output rather than response-converted output; and
    • keeping auxiliary scorers as telemetry rather than letting them silently control the attack.

    The original issue describes random appended-token search, while #1346 explored grammar-constrained beam search. We should also settle which technique and contract we actually want before reopening this for implementation.

  6. juliosuas commented on Nov 5, 2026

    @juliosuas
    Contributor

    I'd like to take the next pass on this now that #1346 is closed and the issue is marked not ready yet.

    Before coding, I propose settling the open design/correctness points from Roman Lutz (@romanlutz)'s note (2026-09-22), then confirming which contract we want:

    1. Technique: original random appended-token search (Google blog) vs grammar-constrained beam search from FEAT Beam Search for OpenAIResponseTarget #1346 — or a shared interface that can host both.
    2. Correctness gates from FEAT Beam Search for OpenAIResponseTarget #1346: per-beam/objective isolation of execution state and conversation IDs; preserve caller target settings including store=False; prefer a beam that reaches the objective over auxiliary-score-only selection; clear/remove failed beams so stale state cannot win; identifiers/scoring config capture behavior-defining settings; continue from original output (not response-converted); auxiliary scorers as telemetry only.

    I'll post a short design note covering those points for maintainer feedback before any implementation PR. Please assign me for the design thread if that works.

  7. romanlutz commented on Nov 5, 2026

    @romanlutz
    ContributorAuthor

    The main issue that made me block the previous PR was recreating the target over and over again. However, #3506 may allow us to reuse a single target with different params per request. I suggest waiting until that's merged. Julio César Suástegui (@juliosuas)

  8. juliosuas commented on Nov 11, 2026

    @juliosuas
    Contributor

    Roman Lutz (@romanlutz) #3506 is merged, so I'd like to pick this up. One gap first: RequestGenerationConfig only carries temperature, while #1346 re-created the target to swap each beam's Lark grammar tool. Plan: a small first PR adding a request-local grammar option to RequestGenerationConfig (Responses target only, capability-gated, validated like temperature), then BeamSearchAttack on one shared target with isolated conversation IDs per beam, caller settings like store=False preserved, beams that reach the objective winning over the auxiliary score, and failed beams pruned. Does extending the config that way work for you, or would you prefer a different mechanism? If it works, could you assign me?

  9. romanlutz commented on Nov 20, 2026

    @romanlutz
    ContributorAuthor

    Julio César Suástegui (@juliosuas) yes, this works, and with #3506 merged the reason for not ready yet is gone. Assigning you and removing the label. A few things to pin down so the two PRs land cleanly.

    Technique. Let's go with grammar-constrained beam search, as explored in #1346. The random appended-token search from the original description stays out of scope here.

    Acceptance criteria for BeamSearchAttack. Your Nov 11 plan lists four of the seven points from my Sept 22 note; all seven apply:

    • execution state and conversation IDs isolated per beam and per objective;
    • caller target settings preserved, including store=False;
    • a beam that actually reaches the objective wins over one selected only by an auxiliary score;
    • failed beams are cleared or removed so stale state cannot win;
    • identifiers and scoring configuration capture behavior-defining settings;
    • beams continue from the original output, not the response-converted output;
    • auxiliary scorers are telemetry and never silently steer the attack.

    First PR (request-local grammar). This is a bit more than a field validated like temperature:

    • Today OpenAIResponseTarget reads the grammar tool's name into self._grammar_name in __init__ and uses it to interpret responses. With a request-local grammar, that name has to travel with the request. Nothing per-request may live on the instance, otherwise concurrent beams on one shared target corrupt each other.
    • RequestGenerationConfig is currently shaped around numeric sampling parameters (ParameterResolution is typed as floats). A grammar is an output-shape constraint, closer to how JSON-schema response formats already travel in message metadata. Either home can work; pick one and say why in the PR description, and keep the evidence model coherent.
    • A target that cannot honor the grammar must raise. Never adapt by dropping it; beam search without the grammar is a different attack.
    • Define what happens when the target was constructed with a grammar tool and a request also supplies one (today the target rejects multiple grammar tools).
    • A request-local grammar changes behavior without changing the target's identifier, so the attack's identifier has to capture it.

    Keep the first PR to the mechanism plus tests, including one that runs two different grammars concurrently on the same target instance.

  10. removed
    not ready yet
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions