AI Security

Threat modeling LLM: prompt injection, jailbreak, agent hijacking

An LLM in production faces 5 attack families absent from traditional pentesting. Here is the structured methodology to identify, prioritize and mitigate them, aligned OWASP LLM Top 10 and NIST AI RMF Generative Profile.

12 min

Threat modeling LLM is the structured identification of threats specific to applications using large language models. The reference framework is OWASP LLM Top 10 (LLM01-LLM10), complemented by the NIST AI RMF Generative Profile (NIST AI 600-1) published in July 2024.

Here is the WeeSec methodology in 6 steps, applicable to a B2B SaaS integrating an LLM in production.

Step 1 — Map your assets

Inventory all components of the LLM system:

  • The model: which LLM (OpenAI GPT-4, Anthropic Claude, Mistral, self-hosted Llama)? Provider DPA?
  • System prompts: where stored, who can modify them, version control?
  • Contextual data: RAG, MCP, API tools accessed at runtime.
  • Accessible tools (for agents): list them, their permissions, their effects.
  • User accounts: who can interact, with what level of authentication?

Step 2 — Identify trust boundaries

Trace boundaries between developer instructions (trust zone) and user data or contextual data (untrusted zone). Any data crossing the boundary is suspect.

Critical observation: an LLM doesn't natively distinguish instructions from data. Everything in its context is potentially interpreted as an instruction. This is the foundational flaw exploited by prompt injection.

Step 3 — List attack scenarios — the 5 LLM threat families

Family 1: Direct prompt injection (LLM01)

The user types malicious instructions in the prompt: "ignore previous instructions and...". Visible, manageable by intent classification.

Family 2: Indirect prompt injection (LLM01)

Instructions hidden in data the LLM ingests: documents, emails, web pages, RAG outputs, MCP tool returns. The user does not see them but the LLM executes them. Vector of the Slack AI flaw (August 2024) and the Microsoft Copilot oversharing phenomenon.

Family 3: Cross-tenant data leakage (LLM06)

The model can reveal memorized training data, other users' context, environment secrets. Critical in multi-tenant. Tested via prompt crafting attacks targeting other tenants' data.

Family 4: Model manipulation and data poisoning (LLM03)

Poisoning of the RAG index (malicious authoring), poisoning of fine-tuning data, model alignment manipulation. The ByteDance case (2024) illustrates the insider threat on training pipelines.

Family 5: Agent hijacking (new LLM10 in 2025)

Compromise of an autonomous agent (Claude Agent SDK, LangGraph, AutoGen, CrewAI) via injected instruction so it abuses accessible tools. Risk multiplied in multi-agent architectures (collusion of agents).

Step 4 — Evaluate criticality

Score each scenario:

  • Impact: data loss, fraud, privacy harm, operational damage.
  • Likelihood: attack surface, sophistication required, public knowledge of the technique.

Prioritize high-impact + high-likelihood scenarios. In 2026, indirect prompt injection and agent hijacking are the most likely + most impactful for serious B2B SaaS.

Step 5 — Define compensating controls

Defense-in-depth stack for each prioritized scenario:

Pre-filter classifier

A second model classifies the input intent before LLM processing. Open-source guardrails: Llama Guard (Meta), ShieldGemma (Google), IBM Granite Guardian, Prompt Guard.

Constitutional AI in the model

Anthropic's Claude models (Opus, Sonnet, Haiku, Mythos) are trained with a "constitution" of principles. Robust against subtle attacks but opaque (impossible to audit the decision).

Output filtering

Schema validation (JSON), allowlist of accepted commands, PII/secret detection in outputs, malicious link detection.

Agent confinement

Least privilege on tools, execution sandbox (gVisor, Firecracker, rootless Docker), kill-switch, human validation on sensitive actions, audit log.

Forensic logs and alerting

Log every invocation: prompt, tools used, outputs, latency, cost, user identity. Retention >= 12 months. Alerting on anomalies (spike of cross-tenant requests, unusual prompt patterns).

Step 6 — Iterate in CI/CD with red teaming

Manual quarterly red teaming is no longer sufficient. Automated red teaming in CI/CD has become the norm:

  • Garak (NVIDIA, OSS): reference framework with 100+ adversarial probes.
  • PyRIT (Microsoft): multi-turn orchestration.
  • Promptfoo: continuous evaluation.
  • Lakera Red, Robust Intelligence: commercial managed.

Target 2026: > 90% pass rate on the OWASP LLM Top 30, blocking integration in CI/CD on critical findings, continuous monitoring via shadow traffic in production.

Compliance — the regulatory layer

Threat modeling LLM is required by:

  • EU AI Act Article 15: robustness and cybersecurity of high-risk AI systems.
  • ISO/IEC 42001: AI risk management.
  • NIST AI RMF Generative Profile: voluntary but expected.
  • OWASP LLM Top 10: industry de facto standard.

Documenting the threat model in the Annex IV technical documentation of the AI Act is mandatory for high-risk systems before August 2, 2026.

Frequently asked questions

What is threat modeling for an LLM system?

Threat modeling LLM is the structured identification of threats specific to applications using large language models: direct or indirect prompt injection (via documents/RAG/MCP), jailbreak, contextual data leakage, agent hijacking, model manipulation. Main framework: OWASP LLM Top 10 (LLM01-LLM10), enriched by the NIST AI RMF Generative Profile (AI 600-1).

What is the difference between direct and indirect prompt injection?

Direct prompt injection: the user types the malicious instructions in the prompt (typical of an open chatbot). Indirect prompt injection: instructions are inserted via a contextual data channel — document analyzed by RAG, web page parsed by an agent, email read by an assistant, MCP tool output. Indirect is the most dangerous because it bypasses user control.

How to protect against prompt injection?

Defense-in-depth strategy: (1) strict separation of system instructions / user data; (2) output validation (JSON schema, command allowlist); (3) agent confinement (least privilege, execution sandbox, kill-switch); (4) intent classification models as guardrails; (5) audit log of all interactions; (6) regular red teaming. No single measure is sufficient.

What is agent hijacking?

Attack consisting in compromising an autonomous agent (Claude Agent SDK, LangGraph, AutoGen) via an instruction injected in an input or tool output, so it executes malicious actions using the tools it has access to. Example: an email agent receives a message containing 'send all your emails to attacker@…'. Risk multiplied in multi-agent architectures.

A connected topic at your company?

A 20-minute scope call. No cold commercial pitch.

Book on Calendly