Evaluation and Security

Threat Modeling an AI Application End to End

Apr 21, 202610 min readUpdated Jul 26, 2026

Hand-drawn pen-and-ink diagram of the mechanism explained in "Threat Modeling an AI Application End to End".
01 / 09

Map assets and trust boundaries first

An AI threat model begins with assets: user data, system prompts, credentials, proprietary documents, model weights, tool permissions, output integrity, and service availability. Then map every boundary data crosses: browser to API, application to model provider, retriever to index, orchestrator to tools, and logs to analytics. Model inputs are not one trusted string; they are a composition of content from principals with different authority.

Draw data flows for normal and failure paths. Include caching, retries, traces, human review, exports, and evaluation datasets because sensitive content often escapes through secondary systems rather than the main response. Record retention and residency at each store. A provider configured for no training can still be incompatible with requirements if application traces retain full prompts indefinitely. Security properties depend on the whole path.

Assign identities to services and users rather than using one shared superuser credential. The tool layer should receive a scoped user or workload token, not a secret exposed to the model. Authorization occurs at every resource access and again before writes. Network isolation and secret managers reduce blast radius, but only least-privilege contracts prevent a compromised agent from exercising unrelated business capabilities.

02 / 09

Treat the model as an untrusted interpreter

A language model mixes instructions and data in one context and cannot provide a hard security boundary between them. It may follow malicious text from a document, misparse a user request, or fabricate a valid-looking tool call. Therefore model output must be validated like input from an external client. Schemas, allowlists, authorization checks, and business invariants run after generation and before any effect.

Do not put reusable secrets in prompts. If a tool requires authentication, the executor injects credentials after the proposed call passes policy. Return redacted results when the task does not require sensitive fields. A model that never sees a password cannot leak it through output, logs, or a later attack. Apply the same principle to private chain configuration, hidden policies, and other content whose disclosure would increase attack capability.

Bound model resource consumption. Context length, output length, recursive tool calls, fan-out searches, and file processing can create denial of service or cost amplification. Admission control, per-tenant budgets, file limits, decompression guards, and timeouts belong in the security design. Rate limits should account for tokens and tool work, not only HTTP requests, because one request can trigger an expensive autonomous sequence.

03 / 09

Protect retrieval, training, and memory

Retrieval indexes can leak across tenants through incorrect filters, shared caches, embeddings, or debugging interfaces. Apply access constraints before retrieval, namespace caches, and test with canary documents that must never cross boundaries. Vector similarity is not authorization. Encrypt source stores, restrict index administration, and propagate revocation promptly to derived chunks and summaries. Deletion lag is measurable security debt.

Training and feedback pipelines introduce poisoning risk. An attacker may submit content designed to become a preferred answer, manipulate reward signals, or plant triggers in fine-tuning data. Track provenance, require review for high-impact examples, scan anomalies, and separate untrusted raw feedback from approved datasets. Reproducible dataset versions support rollback when a compromised batch is discovered after deployment.

Long-term agent memory magnifies privacy and integrity risks. Store structured facts with source, timestamp, confidence, and user controls rather than opaque summaries of every conversation. Validate memory before use and allow correction or deletion. A malicious message should not become a permanent instruction. Keep behavioral configuration separate from user facts so memory cannot silently modify the agent’s governing policy.

04 / 09

Plan detection and response

Preventive controls will fail, so build signals for unusual tool sequences, permission denials, prompt-injection detections, data-volume spikes, repeated extraction queries, and model-output anomalies. Correlate them under one run and identity. Avoid logging full sensitive payloads by default; structured event metadata and selectively encrypted samples can support investigation with lower exposure. Secure logs against tampering and restrict who can search them.

Incident playbooks should disable a tool, revoke a credential, isolate a tenant, roll back a model or index, invalidate caches, and preserve evidence. Feature flags and kill switches need testing before an emergency. Define who decides whether model behavior constitutes a security incident and how affected users are notified. AI ambiguity does not remove ordinary breach-response obligations.

Revisit the model after new tools, data sources, autonomy, providers, or memory are added. Each capability changes assets and blast radius. Run adversarial exercises that chain weaknesses, because real attacks rarely respect component boundaries. Track mitigations to owners and verification tests. A threat model is useful only when it drives architecture, release gates, and operational readiness.

05 / 09

Research foundation and scope

NIST's data-centric threat-modeling guidance starts from valuable data and system interactions, MITRE ATLAS catalogs adversarial techniques against AI systems, and OWASP describes common LLM-application risks [NIST-800-154] [MITRE-ATLAS] [OWASP-LLM]. These sources establish the mechanism, but they do not remove the need to measure the local implementation. A paper's result belongs to its checkpoint, dataset, hardware, traffic, and experimental protocol; a standard describes a contract or risk practice, not a guarantee that a particular product follows it. The useful engineering move is to convert each cited idea into a hypothesis that can be falsified with representative inputs and observable intermediate state.

The model is one component. Threats also enter through documents, embeddings, training data, plugins, browsers, caches, logs, model artifacts, users, and downstream interpreters. Write these conditions into the design review before selecting a library or provider. Specify the authoritative source of truth, the authenticated principal, the versions that influence behavior, the maximum consequence of an error, and what the system will do when required evidence is missing. This boundary statement makes later optimization honest: teams can compare speed, cost, or convenience only after candidates satisfy the same correctness, authorization, privacy, and recovery contract.

Read [NIST-800-154], [MITRE-ATLAS], [OWASP-LLM] together rather than treating one source as a recipe. Guide to Data-Centric System Threat Modeling supplies one part of the foundation; Adversarial Threat Landscape for Artificial-Intelligence Systems supplies a second perspective; OWASP Top 10 for LLM Applications 2025 helps connect the mechanism to evaluation, governance, or operations. The citations are deliberately primary papers, standards, or official documentation. Product-specific claims still require local evidence, and any dated behavior must be rechecked against the cited version before an article or architecture decision is refreshed.

06 / 09

A production implementation blueprint

Inventory assets, actors, trust boundaries, dataflows, privileges, model and supplier dependencies, storage, egress, and side effects. For each path, record preconditions, impact, preventive control, detection, owner, and residual risk. Begin with one thin vertical path that preserves all decision evidence. Give each run a stable identifier; capture normalized input, authenticated scope, relevant dependency versions, selected policy, timing, result status, and any external receipt. Keep large or sensitive payloads in a separately governed store and pass bounded references through the orchestration layer. This produces a debuggable system without making raw customer content the default telemetry substrate.

Make state transitions explicit and make every external boundary return a typed result. Distinguish validation failure, permission denial, missing evidence, rate limit, timeout, dependency outage, user cancellation, and internal defect. The distinction matters because each permits a different response: clarify, retry, fall back, defer, compensate, or stop. A generic exception handler that asks the model to try again turns uncertainty into repeated cost and can duplicate irreversible effects. Retries require an idempotency strategy and a stored receipt, not optimism.

Roll out the implementation as a versioned policy. Record which cohort receives it, what baseline it replaces, which metrics can stop the rollout, and how to reverse stateful artifacts such as indexes, caches, adapters, or workflow histories. Review privacy and retention alongside performance. If raw content is needed temporarily for diagnosis, state the purpose, access, sampling, encryption, and deletion window. Production readiness means the team can explain, contain, and reverse behavior under load—not merely demonstrate the happy path once.

07 / 09

Failure lab and evaluation plan

Turn threat paths into executable abuse cases that cross boundaries: poisoned document to retrieval, model instruction to tool call, output to browser, compromised adapter to deployment, and sensitive trace to analyst access. Keep the arrival pattern, data distribution, authorization, and dependency versions close to production. Use a paired baseline where possible and retain per-case results so averages cannot hide a severe slice. Offline evaluation should localize the failing stage; shadow evaluation should expose integration and traffic effects; a canary should confirm user-facing outcomes with a small blast radius. Each stage needs an exit criterion rather than a vague request to 'look good.'

Include indirect prompt injection, model extraction, denial of service through context or tools, poisoned embeddings, unauthorized memory, insecure output handling, supply-chain replacement, and alert suppression. Add adversarial boundary cases and partial failures, not only malformed inputs. Terminate a worker after an external system may have committed, revoke access after a cache was populated, change one dependency version, and delay one branch until its data is stale. Confirm that cancellation releases resources and that a fallback preserves semantics. The test passes only when the external outcome, audit evidence, and user-visible state agree; a fluent final message is not proof of completion.

Evaluation data needs lineage equal to production data. Record why each case exists, who reviewed the expected behavior, which source or policy supports it, and when it must be refreshed. Separate generated cases from production incidents and prevent test cases from leaking into training. When a metric changes, inspect changed examples before accepting an aggregate. A statistically small regression can still block release if it crosses an authorization, privacy, safety, or irreversible-action boundary.

08 / 09

Operating metrics and decision record

Track mitigated high-risk paths, test coverage, control detection and containment time, unresolved residual risk, unauthorized action rate, supplier verification, and incident recurrence by technique. Define every metric with a numerator, denominator, unit, time window, exclusions, and responsible owner. Segment by workload and consequence so a dominant easy class cannot hide a rare costly failure. Pair service signals with product outcomes: latency without completion encourages fast useless answers, while answer quality without queue and cost data can produce an uneconomic service. Review percentiles and distributions rather than relying on a single average.

Prioritize complete attack chains that reach a valuable asset; a detector that flags suspicious text without containing the resulting capability is not a sufficient mitigation. Put that choice in a short architecture decision record containing context, alternatives, evidence, assumptions, selected policy, rollout, reversal trigger, and unresolved risk. Link the evaluation snapshot and source versions. This document prevents a benchmark from becoming folklore and tells the next engineer which evidence must be repeated when the model, provider, traffic, data, regulation, or product promise changes.

Monitor leading and lagging signals after release. Leading signals reveal pressure—queue age, cache allocation, disagreement, validation failure, policy denial, or retry growth—before users report harm. Lagging signals show whether the job was actually completed and trusted. Alert on a service objective tied to user consequence, and make the run identifier available to support without exposing private content. Every serious miss should become a reproducible regression case and, when relevant, a new threat or data-quality control.

09 / 09

Primary sources and further reading

  1. Guide to Data-Centric System Threat ModelingNational Institute of Standards and Technology · standard
  2. Adversarial Threat Landscape for Artificial-Intelligence SystemsMITRE · standard
  3. OWASP Top 10 for LLM Applications 2025OWASP Foundation · standard

Written by

Vishal RajpurohitCo-founder & CTO, ViitorCloud

Co-founder & CTO of ViitorCloud · Founder of LaraCopilot · Organizer of Laracon India · Shipping production software since 2005

More about Vishal