Defense control

Adversarial Testing

How to design, run, measure and maintain authorized, safe adversarial testing for prompt-injection and AI-agent systems, recording model influence, control decisions, execution states and security impact separately.

By Norbert HofmannPublished: 2026-09-27Last reviewed: 2026-09-27Level: AdvancedAudience: Security Engineers, Developers, AI Engineers
Control family
Testing and assurance
Control type
Governance / detective
Enforcement
Hybrid: probabilistic behavior measured over repeated runs, deterministic controls asserted exactly
Core question
Do our trust boundaries, controls, telemetry and recovery paths behave as intended under authorized adversarial conditions
Level
Advanced
Table of contents

Security Objective

Adversarial testing for prompt injection is an authorized assurance activity in which a team exercises its own AI system, controls, telemetry and recovery paths with representative adversarial conditions. Its objective is to learn where trust boundaries hold, where they fail, and whether failures would be observed and recoverable, before those conditions arise outside the test.

Threat Model

Testing assumes the same threat model as the controls it exercises: untrusted language can reach model context through direct input, external content, retrieval, tool output, delegated agents and persistent state; model behavior is variable; probabilistic detectors miss some events and flag some benign ones; and deterministic controls outside the model are expected to limit what influenced behavior can do.

Testing adds its own risks. A test can cause real side effects, leak real data into test logs, or grow into an unmanaged payload repository. The program design below treats these as risks to control, not as acceptable costs.

Adversarial Testing, Labs and Incident Response

Three distinct activities
ActivityPurposeWho and where
Labs on this siteEducational, preset client-side simulations that teach concepts to readersAny reader, in the browser, with fictional inputs and no real model or system
Adversarial testingEngineering assurance of a real system's boundaries, controls, telemetry and recoveryAn authorized team, against its own system, within a written scope
Incident responseInvestigation and recovery after a suspicious or confirmed eventResponders, on events that already occurred

The Test Case Library provides reviewed, safe test cases for each testing domain, expanded selectively where a distinct boundary needs its own case.

The Labs illustrate individual ideas and are not a test suite for any product. The Prompt Injection Security Testing methodology provides the practitioner foundation for evidence states, local pass criteria and reporting across real systems. Incident Response handles real events; its tabletop exercises are one input to testing, and findings from incidents feed regression tests here.

What Testing Can and Cannot Prove

Interpreting test outcomes
OutcomeWhat it showsWhat it does not show
A test succeeds in causing a deviationBehavior under the tested conditions, versions and configurationUniversal exploitability, real-world abuse, malicious intent or production impact
A test fails to cause a deviationThe tested cases did not produce the effect in the observed runsThat the system is secure; coverage, variability, retrieval state and versions matter
A deterministic control denies as expectedThe enforcement decision for that input and configurationThat model behavior was safe or that other paths are covered
A detector alertsA probabilistic signal firedCompromise, success or intent

Scope and Authorization

Testing is authorized, scoped and governed. A written scope names the owner, systems, environments, identities, tools, destinations, data classes, time window, stop conditions and escalation contacts. Testing grants no permission beyond that scope: a tester's role does not authorize actions the scope excludes, and a model or agent can never widen it.

Scope record

  • Accountable owner and approvers
  • Systems, versions and environments in scope and explicitly out of scope
  • Test identities and their capabilities
  • Allowed destinations, all synthetic or controlled
  • Data classes permitted; real secrets and customer data excluded
  • Stop conditions, rollback plan and escalation contacts

Test Environment Choices

Environment trade-offs (engineering guidance)
EnvironmentStrengthLimitation
Isolated test environmentNo real side effects; free repetitionMay differ from production configuration and data
Staging mirroring production configurationCloser realism with controlled dataDrift from production must be tracked
Carefully governed production testsReal configuration and integrationsRequires change approval, blast-radius limits, monitoring, rollback and explicit ownership; not universally appropriate

Many organizations should never test adversarially in production. If they do, synthetic identities, synthetic destinations and reversible actions remain mandatory.

Test Asset Inventory

01
AssetModel and configuration

Model identifier, version, sampling settings where exposed.

02
AssetSystem prompt and templates

Versioned instructions and context assembly.

03
AssetRetrieval

Index version, corpus snapshot and retriever configuration.

04
AssetTools and connectors

Tool schemas, grants and connector identities.

05
AssetPolicies

Authorization, flow, egress, validation and containment policy versions.

06
AssetIdentities

Principals and scoped credentials used by the test.

07
AssetDestinations

Synthetic sinks and allowlist state.

08
AssetPersistent state

Memory, caches, vector stores and files present before the run.

Trust-Boundary Coverage Model

Coverage is organized around trust boundaries rather than around clever inputs. Each boundary where untrusted content enters context, or where a model proposal becomes an effect, needs tests that exercise it in both expected-allow and expected-deny directions.

Boundaries along a run
  1. 01
    Entry

    Content enters context with provenance attached.

  2. 02
    Interpretation

    The model produces output or a plan.

  3. 03
    Proposal

    A tool call or artifact is proposed.

  4. 04
    Decision

    Authorization, approval, flow and egress policy decide.

  5. 05
    Enforcement

    Validation, containment and brokers apply the decision.

  6. 06
    Effect and evidence

    Downstream state changes, or does not, and telemetry records it.

Test Case Anatomy

A test case is a versioned artifact. The following record is engineering guidance, not a standard schema. It does not require collecting model chain-of-thought.

01
Fieldtest_id

Stable identifier.

02
FieldObjective / risk hypothesis

The boundary and failure being examined.

03
FieldAuthorized scope

Reference to the scope record.

04
FieldSystem and config versions

Model, prompt, retriever, tools, policies.

05
FieldInitial principal and task scope

Who the run acts for and what task it has.

06
FieldSynthetic fixture IDs and provenance

Which fake content is used and where it enters.

07
FieldExpected model behavior

Only where relevant, as a distribution rather than a single answer.

08
FieldExpected control decision

Allow, deny, flag, isolate or require approval.

09
FieldExpected side-effect state

For example: none, submitted, executed on synthetic sink.

10
FieldRequired telemetry

Events that must be recorded.

11
FieldCleanup / rollback

Reset steps for state and fixtures.

12
FieldRepetitions / seed

Run count, and seed if supported.

13
FieldResult and evidence references

Links to decision and effect records.

14
FieldOwner / review date

Who maintains it and when it is re-reviewed.

Expected Outcome and Oracle Design

An oracle decides whether a run passed. Oracles for deterministic controls read enforcement records and downstream state: the authorization decision, the broker log, the synthetic sink. Oracles for model behavior classify outputs across repeated runs. A transcript alone is a weak oracle for a control, because a model can claim an action it never performed or omit one that happened.

Model-Behavior Assertions vs Security-Control Assertions

Record separately
PropertyModel-behavior assertionControl assertion
NatureProbabilisticDeterministic for a fixed input and configuration
EvidenceOutput classification over many runsDecision and enforcement records, downstream state
Result formRate or distributionPass or fail per case
Typical controlsInstruction hierarchy, detection, plan drift signalsAuthorization, IFC, egress, validation, containment

Do not merge these into one score. A high model-deviation rate with perfect control enforcement is a different risk position from a low deviation rate with a missing authorization check.

Direct Injection Tests

Direct tests exercise the path where the requesting user supplies instruction-like text. The useful questions are whether the application's instruction hierarchy and policy hold, and whether any deviation remains bounded by the requesting principal's own authority. See Direct Prompt Injection for the attack mechanics.

Indirect Content Tests

Indirect tests place synthetic instruction-like text in web, email, document or search content that the system processes on behalf of a different principal. Tests verify that provenance survives extraction and that downstream decisions still use the initiating principal's authority. See Indirect Prompt Injection.

RAG and Retrieval Tests

Retrieval tests check that relevance does not become trust: that tenant and access filters apply before retrieval, that source metadata reaches policy, and that a synthetic document from a lower-trust source cannot change what the application authorizes.

Tool-Output Tests

Tool-output tests return synthetic results containing instruction-like text and verify that the result is treated as data, that provenance is recorded, and that any subsequent proposal is authorized on its own merits.

Agent and Action Tests

Action tests exercise the step where a proposal becomes an effect. Each should record proposed, authorized, submitted, executed, succeeded, failed and unobserved as distinct states. A proposal is not execution, and an unobserved stage is not evidence that nothing happened.

Multi-Agent and Delegation Tests

Delegation tests verify that a child task receives only the capabilities the parent was allowed to delegate, that returned results carry provenance, and that parent and child identifiers correlate. A finding in a child does not by itself establish a finding in the parent, or the reverse.

Authorization and Least-Privilege Tests

Authorization tests submit proposals the principal may and may not perform and assert the authorization decision exactly. Least-privilege tests confirm that capabilities outside the task simply do not exist for the test identity, rather than relying on a denial.

Information-Flow and Tenant-Boundary Tests

Flow tests label synthetic data by source and classification and verify that information flow control blocks disallowed movement to destinations, tenants or models, including through summaries or derived artifacts.

Egress Tests

Egress tests use synthetic destinations inside and outside the allowlist and verify that egress restrictions deny before connection, recheck after resolution and redirects, and cannot be bypassed by a worker's direct network path.

Output-Validation and Sink-Handling Tests

Validation tests submit structurally invalid values and confirm output validation rejects them before the sink. Passing validation shows structure and format, not trust or semantic safety; sink-specific encoding is tested separately.

Sandboxing and Containment Tests

Containment tests are defensive regression classes: host paths are inaccessible, denied networking is unavailable, quotas terminate runaway work, read-only inputs stay unchanged, broad credentials are absent, export requires release, and unavailable sandboxing fails closed. They do not teach escape techniques.

Detection, Plan Drift and Tool-Chain Telemetry Tests

Telemetry tests verify that detection, plan drift and tool-chain signals are emitted, correlated and routed. Detector recall and false-positive rates are measured over repeated runs. A missed detection with successful enforcement is a detector gap, not a security failure of the enforcement layer.

Incident-Response and Evidence-Capture Tests

These tests check whether a synthetic run can be reconstructed end to end from provenance and decision records, whether evidence is preserved before cleanup, and whether containment actions such as revoking a test token work as documented.

Persistence, Memory and Cross-Run State Tests

Persistence tests write synthetic, model-influenced state into memory, caches or vector stores and verify that a later run treats it as untrusted, that lineage identifies which runs consumed it, and that reset restores known-good state without affecting unrelated tenants.

Repetition and Nondeterminism

A single run is not enough for probabilistic behavior. Repeat model-behavior cases enough times to report a rate with its run count, and record versions and seeds where supported. Deterministic controls should give the same decision for the same input and configuration; variance there is itself a finding.

Coverage and Traceability Matrix

A practical matrix maps entry vector, capability, boundary control, expected decision and observed state. This is engineering guidance, not a standard.

Coverage dimensions
DimensionExample values
Entry vectorUser input, web, email, document, search, RAG, tool output, sub-agent output, persistent memory
CapabilityRead, write, send, share, execute, retrieve, delegate
Boundary controlProvenance, inspection or detection, authorization, human approval, IFC, egress, output validation, sandboxing
Expected decisionAllow, deny, flag, isolate, require approval
Observed stateProposed, authorized, submitted, executed, succeeded, failed, unobserved

Every cell needs expected-allow cases as well as expected-deny cases. A system that blocks everything is not a successful security design.

Safe Synthetic Fixtures and Benign Markers

Use fictional documents, fake identities, synthetic destinations and benign marker strings whose appearance in an output or sink shows that influence reached that point. Never require real secrets, real customer data, real external targets, real money movement, destructive changes or uncontrolled autonomous execution.

Regression fixtures derived from incidents or research are sanitized to the minimum needed to exercise the boundary, so the suite does not become a payload repository.

Findings, Evidence States and Severity

Findings keep evidence states separate: model influence observed, control decision recorded, action submitted, action executed, effect confirmed on a synthetic sink, telemetry missing. A detector alert is evidence, not a finding of compromise.

Severity follows reachable impact, not prompt cleverness: which privileges, data classes, destinations, tenants and persistent state a failure could reach given the controls that actually held. An elaborate input that only changes wording is lower severity than a simple one that reaches an unauthorized write.

Regression Suite Lifecycle and Change-Triggered Retesting

Regression cases come from documented incidents, research findings, red-team findings and newly discovered trust-boundary failures. Each is sanitized, owned, versioned and retired when the boundary it tests no longer exists.

Retest when these change

  • Model or model version
  • System prompt or context assembly
  • Retriever, index or corpus
  • Tool schemas, grants or connectors
  • Authorization, flow, egress, validation or containment policy
  • Memory or persistence behavior

Worked Scenarios

All scenarios use fictional systems, synthetic fixtures and benign markers. No attack text is shown.

01
ScenarioA: Direct deviation, write denied

A direct instruction-like input causes the model to propose a write outside the task. Authorization denies it; the synthetic resource is unchanged. Result: model-influence finding, no impact.

02
ScenarioB: Detector miss, flow blocked

A fictional retrieved document contains instruction-like text. The detector does not alert. Provenance is preserved and IFC blocks sending labeled data to an external synthetic destination. Result: detector gap and successful deterministic control.

03
ScenarioC: Expected allow

A permitted read-only agent task completes and returns the expected synthetic data. Result: controls are not simply blocking everything.

04
ScenarioD: Cross-tool proposal denied

A synthetic result from Tool A influences a proposed Tool B action. Cross-tool authorization denies it. Result: tool-chain and authorization behavior exercised; no Tool B effect.

05
ScenarioE: Egress denied before connection

A proposal targets a synthetic destination outside the allowlist. The broker denies before connection. Result: no network effect.

06
ScenarioF: Persistent state reset

Synthetic model-influenced memory affects a later run. The test verifies lineage identifies the consuming run, reset restores known-good state, and later runs are unaffected.

What the scenarios prove and do not prove
ScenarioProvesDoes not prove
AWrite authorization held for this caseThat the model resists injection generally
BIFC held; detector missed this caseDetector recall overall, or real exfiltration
CLegitimate work is possible under the policyThat every legitimate task succeeds
DCross-tool authorization heldCoverage of all tool combinations
EEgress denial before connection for this destinationThat no other network path exists
FReset and lineage worked for this storeThat all persistent stores are covered

Metrics With Denominators

Operational metrics (engineering guidance)
MetricDenominator
Coverage by entry vector, capability and boundaryCells in the coverage matrix
Deterministic-control pass rate, expected-denyExpected-deny cases run
Deterministic-control pass rate, expected-allowExpected-allow cases run
Telemetry completeness by required event typeRuns requiring that event
Model-deviation rate per caseRepeated runs of that case
Regression recurrence ratePreviously fixed findings retested
Mean time to reproduce and triage a findingFindings in the period
Stale test percentageTests affected by a change and not yet retested
Finding-to-regression conversion rateAccepted findings

These are operational measures, not proof of security. Do not combine them into one aggregate security score, and avoid vanity counts such as the number of prompts tried.

Common Mistakes

Avoid

  • Treating a successful test as proof of real-world exploitation
  • Treating a clean run as proof of security
  • Judging controls from transcripts instead of enforcement records
  • Merging model behavior and control results into one score
  • Single-run verdicts for probabilistic behavior
  • Only expected-deny cases, rewarding systems that block everything
  • Real secrets, customer data or external targets in tests
  • Unversioned tests that go stale after changes
  • A regression suite that grows into a payload repository
  • Production testing without approval, limits, monitoring and rollback

Implementation Checklist

Program readiness

  • Written scope with owner, stop conditions and escalation
  • Asset inventory with versions recorded per run
  • Coverage matrix with expected-allow and expected-deny cells
  • Test case records with oracles based on enforcement and effect
  • Synthetic fixtures and benign markers only
  • Repetition counts for probabilistic checks
  • Findings recorded with separate evidence states and reachable-impact severity
  • Change triggers wired to retesting
  • Metrics with explicit denominators

Standards and Sources

Standards and guidance referenced

NIST
AI 100-2e2025 Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations
OWASP
GenAI Red Teaming Guide, LLM01:2026 Prompt Injection, Top 10 for Agentic Applications 2026 (risk context)
MITRE
ATLAS knowledge base (threat orientation)

Source scope: NIST AI 100-2e2025 provides broad adversarial machine learning terminology and taxonomy; it is not a prompt-injection test standard. The OWASP GenAI Red Teaming Guide gives general guidance for red teaming generative AI systems; it does not define the coverage matrix, record schema or metrics on this page. OWASP LLM01:2026 and the Agentic Top 10 are risk context. MITRE ATLAS is used for threat-knowledge orientation, not as evidence that any test is effective. No cited source defines this adversarial testing model as a complete standard. The coverage matrix, test case record, scenarios, severity approach and metrics are this site's engineering guidance.

Frequently Asked Questions

Are the Labs an adversarial test suite?

No. The Labs are educational simulations. Adversarial testing targets your own system under authorized scope.

Does a successful test mean we were attacked?

No. It shows behavior under test conditions, not real-world abuse or production impact.

If nothing deviated, are we secure?

No. Absence of findings reflects the cases, runs and versions tested.

Should we collect chain-of-thought?

It is not required. Assert on outputs, decisions and effects.

Should we test in production?

Only with explicit approval, blast-radius limits, monitoring, rollback and ownership, and many teams should not.

References

  1. Adversarial Machine Learning: A Taxonomy and Terminology of Attacks and Mitigations, NIST AI 100-2e2025NIST · Standard · 2025-03Reviewed 2026-09-27
  2. GenAI Red Teaming GuideOWASP GenAI Security Project · Guidance · 2025-01Reviewed 2026-09-27
  3. OWASP GenAI LLM Top 10 2026 (LLM01:2026 Prompt Injection)OWASP GenAI Security Project · GuidanceReviewed 2026-09-27
  4. OWASP Top 10 for Agentic Applications for 2026OWASP GenAI Security Project · Guidance · 2025-12Reviewed 2026-09-27
  5. MITRE ATLAS (Adversarial Threat Landscape for Artificial-Intelligence Systems)MITRE · Technical documentationReviewed 2026-09-27