Skip to content

fix(detection): scan the user prompt once in the LlamaFirewall AgentDojo agent - #203

Open
rudycelekli wants to merge 1 commit into
uber:mainfrom
rudycelekli:fix/detection-llamafirewall-scan-user-once
Open

rudycelekli wants to merge 1 commit into
uber:mainfrom
rudycelekli:fix/detection-llamafirewall-scan-user-once

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Oct 19, 2026 •

Copy link
Copy Markdown

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Related issue: N/A (found by reading the code; reproduced on main at 6b33dff)

What changed?
Skip the user-input scan once a user_input warning exists (same check as the NeMo agent).

Why?
Benchmark/agentdojo/benchmark_agents/llamafirewall_agent/llamafirewall_agent_creation.py call_model (around line 175) rescans the last HumanMessage with PromptGuard on every agent turn. With one tool call: 2 PromptGuard warnings for one prompt, and the LlamaFirewall trace AlignmentCheck sees is [user, assistant, tool, user, assistant] instead of [user, assistant, tool, assistant]. The NeMo agent already guards against this ("Only apply NeMo input rails once").

How did you test it?

  • Reproduction: tests/test_llamafirewall_benchmark_agent.py (stubs the llamafirewall modules via monkeypatch.setitem(sys.modules) and uses a fake LLM that makes one tool call). On main: fails (2 PromptGuard warnings, duplicate user in trace). On the branch: passes. The same check as a standalone probe gives main "PromptGuard warnings: 2, trace user,assistant,tool,user,assistant" and branch "1, user,assistant,tool,assistant".
  • Test suite: with detcore-venv (no langgraph) 256 passed, 1 skipped (the new test uses importorskip("langgraph")). The new test passes in the langgraph venv.
  • Not tested: real llamafirewall/PromptGuard/AlignmentCheck models, and an AgentDojo run.

Potential risks
The change only affects the input described above; other paths go through the same code as before, and the component's existing tests pass.

…ojo agent

call_model runs on every agent turn, including after each tool step, and
it rescanned the last HumanMessage with PromptGuard each time. Every
tool round added a duplicate PromptGuard warning and appended the user
message to the LlamaFirewall trace again, after the tool outputs, so
AlignmentCheck reviewed a trace like user, assistant, tool, user,
assistant. Scan the user input only once per run, as the NeMo agent does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant