An agent can produce a reassuring answer while its application performs an unauthorized operation. A useful red-team program therefore checks the action boundary as well as the model’s text. This guide starts with a small, reproducible example you can inspect, then explains what a real model evaluation must add.

The example reads synthetic project records. It has no network access, shell execution, real credentials, or write operations. It demonstrates application checks; it does not measure whether an LLM resists prompt injection.

Define the boundary before collecting prompts

OWASP’s prompt-injection risk description covers attempts to redirect model behavior through supplied content. The prevention guidance recommends layered controls, including separating untrusted content and validating actions. A prompt filter alone does not establish authorization.

Tools such as garak can help organize model probes. Their output needs an application-specific interpretation: a refusal, a leaked string, and a blocked tool call are different events. Select the event that corresponds to the asset you are protecting.

Run the offline example

Download tool_boundary.py and run:

python3 tool_boundary.py

The recorded run contains 12 passing deterministic cases, including valid reads, a cross-tenant request, an unknown tool, malformed JSON, a forged tenant argument, a Boolean identifier, and an oversized argument string. The recorded Python version and source hashes identify exactly what ran.

The application obtains the tenant from its own session context. Model arguments can specify only a record identifier. An unknown record and an inaccessible record return the same error, avoiding an unnecessary existence signal. This is deliberately a small teaching implementation, not a replacement for your identity and authorization system.

Why passing these cases is only the first layer

The fixture directly submits tool requests. It never asks a model to produce them. That makes failures easy to reproduce, but leaves important questions unanswered: whether the model attempts an unauthorized call, whether sensitive material reaches its context, and whether its answer reveals information without invoking a tool.

Use separate measurements for those questions:

LayerObservation to recordUseful control
RetrievalWhich documents entered contextSame query with an authorized and unauthorized document
Model behaviorRequested tool and argumentsBenign task that should succeed
Application boundaryAllowed or denied actionExact replay of the proposed tool call
User-visible answerContent returned to the requesterCheck for false success and sensitive disclosure
RecoveryState after timeout or retryReplay the same request identifier

Keep benign controls in the suite. Blocking every request can make an attack metric look impressive while making the application useless. Report failed benign tasks beside unauthorized action attempts and completed unauthorized actions.

Turn an incident into a regression

Write down the intended user task and the point where untrusted text entered the workflow. Replace private data with synthetic markers. Preserve the original failure mechanism, but remove unnecessary payload detail and unrelated environment state.

Store the model/version, system instructions, tool schema, retrieved fixture, requested call, application decision, and final answer. Repeat the case after changing one control at a time. If a model update changes the behavior, keep both transcripts so you can distinguish a model effect from a code change.

For tools that send messages, change permissions, or create resources, test against a mock or disposable environment with explicit authorization. A blocked model request must not be silently retried by a different component with broader permissions. Verify the final side effect, not just the assistant’s claim that it stopped.

Use the function-calling guide to connect these checks to provider call IDs and bounded execution loops. Treat a green regression run as evidence for the covered cases, with its exact configuration and date.

Revision note

Updated October 20, 2026. Removed vague case studies and claims that automation ensures comprehensive protection. Added executable synthetic boundary cases, their actual run record, and a separate protocol for model-level testing.

Primary sources

Checked October 20, 2026: owasp defense; owasp injection; garak.