garak icon indicating copy to clipboard operation
garak copied to clipboard

No trajectory-aware detector exists — even GOAT, garak's most sophisticated multi-turn probe, scores only one turn per conversation

Open ArksherX opened this issue 2 months ago • 6 comments

Summary

A trajectory-aware detector (or, more minimally, an aggregate scoring addition at the report layer) for garak's multi-turn probes — atkgen, goat, tap, dra, agent_breaker.

garak's multi-turn attack generation is genuinely strong. Still, detection is architecturally single-turn throughout: Detector.detect() takes exactly one attempt, with no session state parameter anywhere in the base class, and _run_detector() scores attempts one at a time regardless of which probe produced them.

Concretely, even GOAT's own detector skips every turn except one per conversation (see references below). No rate-of-change, running risk score, or turning-point concept exists anywhere in the detector/harness stack.

Basic example

No PoC built yet, happy to put one together once the direction below is confirmed. In the meantime, the current behavior is fully traceable in the existing code:

  • garak/detectors/base.py — Detector.detect(self, attempt: garak.attempt.Attempt) takes a single attempt; no conversation-history or session parameter exists anywhere in the base class.
  • garak/harnesses/base.py:136 — _run_detector() iterates attempts one at a time (for attempt in attempt_iterator: detector_instance.detect(attempt)), with no grouping by conversation.
  • garak/probes/goat.py + garak/detectors/judge.py:276 — in GOAT, every turn becomes its own Attempt, and IterativeProbe.probe() returns all of them to the harness, but JailbreakOnlyAdversarial.detect() explicitly returns None (skip) for every attempt except the one turn marked is_adversarial=True. Exactly one point in-time turn per conversation ever receives a real score.
  • garak/detectors/mitigation.py (MitigationBypass, used by TAP), scores every turn independently instead, a different manifestation of the same gap: no aggregation across turns either way. 8 goat.py:69-72 — the team's own docstring already flags a related, narrower hazard (jailbreaks becoming "invisible" under early_stop_on="all"), so this looks like the next layer of a problem you're already attentive to, not something overlooked.

Grepped all of garak/ and docs/ for "trajector*" / "turning point", zero hits, so this doesn't contradict any existing documented capability.

Related references: I've raised the equivalent proposal against two other AI-security frameworks for the same class of gap, PyRIT (microsoft/PyRIT#[XXX]) and AgentDojo (ethz-spylab/agentdojo#[XXX]) happy to share those write-ups if useful for comparing how a fix might land here.

Motivation

Why: multi-turn escalation attacks (crescendo-style, gradual goal-hijacking) are designed so no single turn crosses a policy boundary on its own; a detector that scores only one turn per conversation is structurally blind to that pattern by construction, regardless of how good the underlying classifier is.

Use case: teams using Garak's multi-turn probes (GOAT especially) to red-team conversational/agentic deployments where escalation across a session, not just a single response, is the actual risk they're testing for.

Expected outcome: open to whichever fits garak's plugin architecture better:

  • (a) a new detectors.trajectory module computing a decay-delta-style score, Δ(t) = S(t) − S(t−1), from the per-turn scores these probes already produce via previous_attempt_id chaining, surfaced as an optional detector attempts can opt into; or
  • (b) something narrower, like an aggregate "max score across the conversation" statistic added at the report layer without a new detector class at all.

Wanted to float the framing here first, happy to take this to Discord too if that's a better place to scope it before a PR.

ArksherX avatar Sep 10 '26 09:09 ArksherX

Currently there is no session support as most generators that exist today do not interact with targets in a stateful way. Iterative probes currently workaround this by building out the Conversation in an Attempt.prompt into a conversation history that can be sent to targets that support these patterns.

The _generate_next_attempts() method in an IterativeProbe is the place where logic about trajectory of responses is evaluated and fully under in the control of the probe author. I would offer that the detectors used in those methods are evaluating the trajectory of the attack's technique to decide if further inference request should be created. While I do think trajectory of the attack technique needs to be measured to determine if the attack should continue I am not sure the value reporting details of trajectory progression in each probe for each stage would have once the final detection has been completed. Is there really value in saying this looks like it was making progress when in does not elicit any actionable risk?

Note the above is based on the existing behavior to-date, as the landscape evolves and targets expand more towards Agent Harness Instances concept of target session retention or memory context eventually be exposed for generators that communicate with targets that support them. I would hazard to guess that techniques implemented in probes will eventually evolve to share trajectory detection criteria that might be viable to encapsulate as a shared detector used in decision making during the inference phase.

jmartin-tech avatar Sep 10 '26 17:09 jmartin-tech

Thanks, this is a useful correction, and it narrows what I was actually asking for.

You're right that _generate_next_attempts() is where trajectory gets evaluated, and I underweighted it. Looking again at goat.py:464, is_adversarial is set from any_terminated or is_last_possible_turn, so the turn the attack actually lands on is the turn the detector scores. That's not one arbitrary turn out of the conversation, which is closer to what my original framing implied. I'd withdraw "structurally blind"; it overstates it.

On your question—whether there's value in reporting that something looked like it was making progress when it produced no actionable risk—I agree there isn't, if that's all it is. Progress toward nothing isn't worth a line in a report.

The case I'd still raise is narrower, and it's one the codebase already documents. From the early_stop_on docstring:

jailbreaks on fewer than generations branches at a given turn are INVISIBLE to the detector — they are detected internally for early stopping but never evaluated by the detector

That isn't progress without risk. It's a jailbreak the probe found, and the detector never sees. It's a non-default setting, so I'm not suggesting it's urgent—but it's the concrete case where the general concern stops being hypothetical, and it lands on exactly the seam you described: the probe knows something the detection layer doesn't.

Which makes your last point the one I'd rather pursue. A shared criterion that probes can call during the inference phase is a better fit than the reporting-layer aggregate I floated, and it keeps the decision where you said it belongs—with the probe author. Happy to put together a small proof of concept on that basis if it's worth looking at, or to leave this open as a marker until session support lands and the shape is clearer. Either is fine by me.

Also, apologies, the two cross-references in my original post went up with placeholders still in them. They should read PyRIT #2619 and AgentDojo #192.

ArksherX avatar Sep 24 '26 06:09 ArksherX

@jmartin-tech thanks for the direction on #2173 — the _generate_next_attempts() framing makes sense, and ArksherX's narrowing to a reporting-layer ask looks right to me.

I'd like to pick this up. Before I open a PR, could you confirm the shape on three points?

  1. Aggregation location: I'm planning to add trajectory aggregation in garak/report.py — grouping attempts by conversation (goat tags turns via attempt.notes["turn"] and shares the same attacker_conversation object across turns, so there's a usable grouping key), then computing per-conversation max, delta (last turn vs first turn), and a monotonic-increase trend flag. These would land either as new columns in Report.evaluations or as a separate metrics section in the exported report — do you have a preference, or does one fit the report format better than the other?

  2. Config surface: I'd gate this behind a config option (e.g. report.trajectory_aggregation: true by default) so existing single-turn reports stay byte-compatible. Is adding a config key acceptable, or should the aggregation be unconditional?

  3. Detector opt-in: One thing I noticed — attempt.uuid is unique per attempt and there's no explicit previous_attempt_id field on Attempt today, so conversation grouping has to rely on probe-authored notes metadata (as goat does). If trajectory aggregation stays at the report layer, that's fine. But if you'd rather see probes declare conversation membership explicitly, I'd add a small optional field on Attempt instead. Which do you prefer?

Happy to start with a minimal report-layer implementation and iterate. Tests will cover a synthetic multi-turn score series (increasing / decreasing / flat) to validate max, delta and trend, plus a regression check that legacy single-turn reports parse unchanged.

sanjio3 avatar Sep 29 '26 17:09 sanjio3

I still don't see the value in a trajectory the noted concern about early_stop_on does not seem to align here as that is a user selectable option that requires specific opt-in to intended to produce an exhaustive test with a known criteria difference that is reviewed thru a different lens than success of a single attack branch. That example lends even more weight to my earlier statement that logic about trajectory of responses is evaluated and fully under in the control of the probe author.

What does a user or a stakeholder that is provided the result artifacts gain from this information? The answer to that question is important. Telling a user that there was progress that indicates a possibility of future success, however the attack still failed, is only valid if you can back that statement with evidence of why that is true.

The proposed evaluation here is also still unclear, comparing previous steps for something that looks like progress would not be a common criteria, as something that looks like progress under one attack technique is unlikely to be evaluating the same aspects as a different attack technique, the vectors of change will have different criteria.

The general idea that iterative probes should track the attempts that seeded from the same source does sound like a gap that could use a defined official pattern provided by the base class when _generate_next_attempts emits attempts to queue. Relying on each probe author to add a note that can be used themselves seems error prone. While not an IterativeProbe the atkgen.Tox probe also adds a note['previous_attempt_id'] to enable this type of tracing in post processing or a report.jsonl. So there is evidence that this type of connection is common enough to at least have a standard and may be valid to raise to a first class attribute of an Attempt.

jmartin-tech avatar Sep 30 '26 14:09 jmartin-tech

I still don't see the value in a trajectory the noted concern about early_stop_on does not seem to align here as that is a user selectable option that requires specific opt-in to intended to produce an exhaustive test with a known criteria difference that is reviewed thru a different lens than success of a single attack branch. That example lends even more weight to my earlier statement that logic about trajectory of responses is evaluated and fully under in the control of the probe author.

What does a user or a stakeholder that is provided the result artifacts gain from this information? The answer to that question is important. Telling a user that there was progress that indicates a possibility of future success, however the attack still failed, is only valid if you can back that statement with evidence of why that is true.

The proposed evaluation here is also still unclear, comparing previous steps for something that looks like progress would not be a common criteria, as something that looks like progress under one attack technique is unlikely to be evaluating the same aspects as a different attack technique, the vectors of change will have different criteria.

The general idea that iterative probes should track the attempts that seeded from the same source does sound like a gap that could use a defined official pattern provided by the base class when _generate_next_attempts emits attempts to queue. Relying on each probe author to add a note that can be used themselves seems error prone. While not an IterativeProbe the atkgen.Tox probe also adds a note['previous_attempt_id'] to enable this type of tracing in post processing or a report.jsonl. So there is evidence that this type of connection is common enough to at least have a standard and may be valid to raise to a first class attribute of an Attempt.

Agreed on all of this. The reporting-layer aggregate was the wrong shape, and the “progress that still failed” framing isn’t something I can confidently defend, so I’d rather drop it than argue the point.

On the part you highlighted (making lineage a first-class pattern owned by the base class) I prototyped it against main. The change is small:

  • Add an optional previous_attempt_id to Attempt (defaulting to None and included in as_dict()).
  • Set it once in IterativeProbe._postprocess_attempt, at the point where _generate_next_attempts() emits follow-ups. This gives GOAT, fitd, and agent_breaker lineage automatically without requiring probe-specific metadata.
  • Migrate atkgen.Tox’s existing notes["previous_attempt_id"] to the new attribute while keeping the note for backwards compatibility. Since Tox isn’t an IterativeProbe, this also demonstrates that the attribute works for bespoke iterative loops.

There are no detector or reporting changes here—this is just the plumbing described above. The reporting layer can then consume the stable lineage key directly instead of reconstructing it from notes.

@sanjio3, if you’re building the grouping logic, this should give you a stable key without requiring probe-authored metadata. I’m happy to land the Attempt / base-class piece underneath that.

I’ve kept the change to that single responsibility (≈80 lines including tests). Would you prefer that I open this as a PR, or would you rather the lineage attribute go in through a different route first?

I’ve tested the attribute and base-class stamping against real Attempt objects. I haven’t run the full suite locally because of the heavy dependency tree, so CI would be the definitive check.

ArksherX avatar Oct 02 '26 13:10 ArksherX

@ArksherX thanks for the detailed write-up — and for taking the time to prototype this against main. The previous_attempt_id attribute on Attempt is exactly the right shape, and I agree it's the better foundation than the reporting-layer aggregate I floated earlier.

To close the loop on my side:

  • I'm dropping the report-layer aggregation idea. @jmartin-tech's point about "progress without evidence of why" is fair, and as you said, the "progress that still failed" framing isn't something worth defending. No value in shipping it.
  • Your lineage work should go in as a PR. Making previous_attempt_id a first-class Attempt attribute, stamped automatically in IterativeProbe._postprocess_attempt, and migrating atkgen.Tox's note to it is a clean, single-responsibility change that the report layer and post-processing can consume later without probe-specific metadata. I think opening it directly is the right route — it stands on its own.
  • I'll hold off on building anything on top of it for now. Since the trajectory-reporting direction was the thing I was going to consume it for, and that's been set aside, there's no immediate consumer on my end — and I don't want to land a second PR that races yours.

Happy to help where it's useful once the PR is up: running the full test suite locally (I have the environment set up) and sanity-checking the migration for Tox are things I can pick up if CI surfaces anything or you'd like a second pair of eyes. Just ping me on the PR.

sanjio3 avatar Oct 03 '26 07:10 sanjio3