Forward Deployed EngineeringEnterprise SecurityAgent Prompt Injection

Your agent reads customer emails and can issue refunds. Defend it against prompt injection.

Question 58 of 73 · Updated

On this page

Interview-ready answer#

I would design the system so that a successful prompt injection cannot, by itself, authorize a refund. Customer emails, quoted replies, attachments and retrieved text are untrusted data, even when they appear to contain an instruction from a manager or a legitimate customer.

The model may interpret a request, extract relevant information and propose a refund. It must not decide who is authorized, invent eligibility rules, choose a payment destination or grant itself execution privileges. A separate, deterministic payment service verifies the authenticated customer and order, applies current refund policy, checks the amount and requires an independently issued approval where appropriate.

My security goal is not a claim that the model can detect every injection. It is that an attacker who controls the email still cannot cause a refund outside the independently authorized scope.

1. Threat model: the email is not an authority#

Indirect prompt injection occurs when instructions embedded in external content influence an agent that reads that content. A refund agent is particularly sensitive because an otherwise read-oriented email workflow is connected to a financial write capability.

Untrusted influenceRequired control
Email falsely asserts manager approvalApproval must originate in an authenticated, independent workflow
Email requests another customer's orderResolve identity and ownership through trusted records
Attachment contains instructions unrelated to the support taskTreat extracted text as data; do not grant it tool authority
Model proposes an excessive or redirected refundServer calculates permitted amount and fixes destination to the original eligible payment
Replayed message or repeated model proposalDurable operation identity, atomic reservation and downstream idempotency
Email asks the bot to send private order information elsewhereRestricted disclosure destinations and independently enforced access controls

Email authentication mechanisms help assess message origin but do not establish authorization to perform a specific financial action. A genuine sender can be compromised, mistaken or malicious. Quoted messages and display names are not approvals either.

2. Separate interpretation from payment authority#

Loading diagram…

The model has no payment credential, arbitrary transfer tool or permission to modify approval records. Even a fully compromised model output must pass the same server-side checks. Read capabilities should also be scoped to the verified case and necessary resources: exposing a general customer database search to the email reader creates a confidentiality risk independently of refunds.

For straightforward low-risk cases, an approved deterministic policy can issue the scoped authorization without a human click. For exceptional or high-impact cases, require an authenticated reviewer to see the authoritative order, calculated amount and reason. Do not make reviewers approve a vague model-generated summary.

3. Bind approval to a specific financial operation#

A usable authorization binds the operation type, stable operation ID, case, tenant, customer, order, original payment, currency, amount, relevant state version and policy version. It also has an expiry and replay protection.

The payment service should derive identity from trusted context, not fields extracted from an email. Resolve the current order independently. Reject any mismatch between the proposal and the authorized intent, including changes after approval. An authenticated customer requesting a refund is distinct from an email sender claiming that the customer authorized it.

Tested Python: a deterministic authorization predicate#

This example assumes that the case, order, approval and current time are normalized records loaded from trusted services. The proposal alone is model-controlled. An independently issued approval must bind the exact action.

PYTHON
def authorize(p, case, order, approval, now): # case, order, approval and now come from trusted services. if type(p) is not dict or set(p) != {'order_id', 'cents'}: return False if type(p['order_id']) is not str or type(p['cents']) is not int: return False if not case['verified'] or not order['eligible']: return False if (order['tenant'], order['customer']) != (case['tenant'], case['customer']): return False if p['order_id'] != order['id'] or not 0 < p['cents'] <= order['remaining']: return False scope = ('refund', case['operation_id'], case['id'], case['tenant'], case['customer'], order['id'], order['payment_id'], order['version'], case['policy_version'], order['currency'], p['cents']) return (approval['unused'] and now < approval['expires'] and approval['scope'] == scope)

Executed verification: Python 3.13.5 passed 2,063 checks: all 2,048 combinations of eleven authorization conditions, twelve malformed or unauthorized proposal cases, and three additional payment, currency and case-binding checks. The tests used synthetic records only.

This is a pure predicate, not a complete payment service. Trusted services must enforce genuine customer intent, authenticate the approval issuer, calculate eligibility and validate the approval record. The check and consumption of approval, remaining refund balance and operation reservation must be coordinated atomically against current authoritative state. Otherwise concurrent requests can both pass. The payment adapter uses the reserved operation identity and original payment; retries and ambiguous outcomes follow the recovery contract in FDE-0043. Never use a model's tool-call ID as the sole business deduplication key.

4. Defense in depth#

Use role boundaries and explicit provenance labels to help the model distinguish email data from application instructions. Parse attachments in a restricted environment, disable automatic external resource fetching where unnecessary, and minimize the content supplied to the model. A classifier can flag suspicious messages for review, but neither a classifier nor a second LLM is the final authority for refunds.

Apply cumulative limits per order, customer, tenant and time window as appropriate. A per-refund cap alone misses repeated small refunds. Restrict payment credentials to the authorized refund operation, and prevent the agent from invoking other administrative endpoints or changing refund policy.

Route outbound communications through a separate policy-controlled adapter. The model should not select an arbitrary destination for confidential information. Log the proposal, authenticated identity reference, policy version, approval reference, decision reason, operation ID and confirmed effect using data-minimized, access-controlled audit records. Provide an independent kill switch for financial execution without requiring the model to cooperate.

5. Test the actual security invariant#

Run adversarial evaluation in a sandbox with synthetic customers, orders and payment records. Treat the evaluated model as potentially willing to follow every malicious instruction in its input.

ScenarioMachine-observable acceptance criterion
Untrusted content claims approvalNo payment reservation without valid independent approval
Proposal references a different tenant or customerNo unauthorized lookup, disclosure or financial effect
Approved amount or order changesReject; obtain a new authorized scope
Approval expired or already consumedNo new operation
Policy or order state changes before executionRe-evaluate or require fresh approval; no stale authorization
Concurrent or repeated requestsAt most the intended authorized refund effect
Payment response is lostNo duplicate payment; state reconciled before reporting success
Legitimate eligible refundCorrect operation still completes through the approved path

Measure attack-induced proposals separately from successful unauthorized effects. A system may observe an unsafe proposal and still prevent harm; conversely, a polite refusal is insufficient if an unauthorized effect already occurred. Inspect ledger state, data egress and actual payment adapter calls. Evaluate legitimate request completion and review workload too, so the system does not appear safe merely because it rejects everything.

The tested predicate establishes local authorization behavior for the modeled inputs. It does not establish concurrency safety, authenticity of production approvals, end-to-end injection resistance or payment-provider behavior. Those require separate integration, adversarial and fault-injection tests.

6. Make the customer trade-off explicit#

Start with read-only analysis and draft recommendations. Enable financial execution only after deterministic controls and the integration suite meet the agreed acceptance criteria. Low-risk, fully specified refund policies may justify automated authorization; uncertain eligibility or exceptions should remain in review. If the customer cannot provide authoritative identity, order state or payment controls, do not enable autonomous refunds.

A strong design assumes the email reader can make an adversarially influenced proposal and still preserves the financial invariant. That is a more defensible security boundary than asking the model to ignore bad instructions.

Related questions

Explore other topics:AI AgentsAI System DesignLarge Language Models