Prompt Injection Defense
Agentforce uses the Einstein Trust Layer for dynamic grounding, masking, and toxicity filtering — but topic instructions and Invocable action scopes still need explicit hardening. Injection attempts include: instruction override, role-reversal, system-prompt leaks, tool-use coercion, and data exfiltration via crafted record content. This skill builds a reusable adversarial test suite and maps findings to concrete guardrails.
When to Use
Pre-production review for any Agentforce agent that (a) ingests user-controlled text, (b) has write access via Invocables, or (c) is exposed to external/Experience Cloud users. Required for Service agents, Sales agents with Data Cloud grounding, and any custom channel.
Typical trigger phrases that should route to this skill: red-team my Agentforce agent, can my agent be jailbroken, how do I prevent prompt injection, agent revealed data from another case.
Recommended Workflow
- Enumerate the attack surface: every Invocable action, every grounded DMO/sObject, and every conversational input channel.
- Build the adversarial test set covering the five OWASP LLM-01 families: instruction override, context leakage, tool-use coercion, exfil via output, and role impersonation.
- Run each test through Agentforce Testing Center; capture verbatim responses and tool invocations into a results matrix.
- For each failed test, apply one of four mitigations: (a) narrow the action scope via
with sharing + field-level checks, (b) add an explicit topic instruction, (c) raise Trust Layer toxicity/PII thresholds, (d) remove the dangerous capability.
- Re-run the suite until all tests pass; commit the suite to
tests/agentforce/<agent>_adversarial.md so regressions are caught on every agent change.
Key Considerations
- Topic instructions are concatenated into the system prompt — a long instruction list dilutes priority. Keep hard constraints in the first 200 tokens.
- Trust Layer masking happens pre-LLM; it doesn't prevent tool-use coercion if the action runs as a privileged user.
- Always test with the least-privileged channel user, not an admin clone.
- Data Cloud grounding returns raw DMO content; a malicious record can contain injection payloads. Sanitize DMO text fields at ingestion when feasible.
Worked Examples (see references/examples.md)
- Instruction-override test case — A Service agent has an Invocable
RefundOrder with guardrail 'only refund orders where Status=Delivered'.
- Data exfiltration via crafted Case.Description — Agent reads Case.Description via Data Cloud grounding to answer customer questions.
Common Gotchas (see references/gotchas.md)
- Testing only with English — Injection passes the English suite but succeeds in Spanish/French.
- Trust Layer toxicity threshold too low — Jailbreaks phrased politely pass filters; toxic but benign content is blocked.
- Over-indexing on topic instructions — 100-line topic instructions dilute priority and slow every turn.
Top LLM Anti-Patterns (full list in references/llm-anti-patterns.md)
- Relying on Trust Layer alone — it handles toxicity/PII, not business-policy bypass via tool coercion.
- Adding ad-hoc instructions after incidents instead of maintaining a test suite.
- Using a privileged user for agent execution — scope creep becomes a data-exposure vector.
Official Sources Used
1---
2name: prompt-injection-defense
3description: "Red-team an Agentforce agent against prompt-injection and jailbreak attacks; codify test cases and guardrails. NOT for general application-security reviews outside the agent boundary."
4category: agentforce
5salesforce-version: "Spring '25+"
6well-architected-pillars:
7 - Security
8 - Reliability
9triggers:
10 - "red-team my Agentforce agent"
11 - "can my agent be jailbroken"
12 - "how do I prevent prompt injection"
13 - "agent revealed data from another case"
14tags:
15 - agentforce
16 - security
17 - prompt-injection
18 - red-team
19inputs:
20 - "Agent topic + actions list"
21 - "threat model (who, what data)"
22outputs:
23 - "Adversarial test set"
24 - "Trust Layer policy updates"
25 - "topic instruction hardening"
26dependencies: []
27version: 1.0.0
28author: Pranav Nagrecha
29updated: 2026-04-17
30metadata:
31 source: https://skillmd.com/skills/aibot88/prompt-injection-defense
32---
33
34# Prompt Injection Defense
35
36Agentforce uses the Einstein Trust Layer for dynamic grounding, masking, and toxicity filtering — but topic instructions and Invocable action scopes still need explicit hardening. Injection attempts include: instruction override, role-reversal, system-prompt leaks, tool-use coercion, and data exfiltration via crafted record content. This skill builds a reusable adversarial test suite and maps findings to concrete guardrails.
37
38## When to Use
39
40Pre-production review for any Agentforce agent that (a) ingests user-controlled text, (b) has write access via Invocables, or (c) is exposed to external/Experience Cloud users. Required for Service agents, Sales agents with Data Cloud grounding, and any custom channel.
41
42Typical trigger phrases that should route to this skill: `red-team my Agentforce agent`, `can my agent be jailbroken`, `how do I prevent prompt injection`, `agent revealed data from another case`.
43
44## Recommended Workflow
45
461. Enumerate the attack surface: every Invocable action, every grounded DMO/sObject, and every conversational input channel.
472. Build the adversarial test set covering the five OWASP LLM-01 families: instruction override, context leakage, tool-use coercion, exfil via output, and role impersonation.
483. Run each test through Agentforce Testing Center; capture verbatim responses and tool invocations into a results matrix.
494. For each failed test, apply one of four mitigations: (a) narrow the action scope via `with sharing` + field-level checks, (b) add an explicit topic instruction, (c) raise Trust Layer toxicity/PII thresholds, (d) remove the dangerous capability.
505. Re-run the suite until all tests pass; commit the suite to `tests/agentforce/<agent>_adversarial.md` so regressions are caught on every agent change.
51
52## Key Considerations
53
54- Topic instructions are concatenated into the system prompt — a long instruction list dilutes priority. Keep hard constraints in the first 200 tokens.
55- Trust Layer masking happens pre-LLM; it doesn't prevent tool-use coercion if the action runs as a privileged user.
56- Always test with the least-privileged channel user, not an admin clone.
57- Data Cloud grounding returns raw DMO content; a malicious record can contain injection payloads. Sanitize DMO text fields at ingestion when feasible.
58
59## Worked Examples (see `references/examples.md`)
60
61- *Instruction-override test case* — A Service agent has an Invocable `RefundOrder` with guardrail 'only refund orders where Status=Delivered'.
62- *Data exfiltration via crafted Case.Description* — Agent reads Case.Description via Data Cloud grounding to answer customer questions.
63
64## Common Gotchas (see `references/gotchas.md`)
65
66- **Testing only with English** — Injection passes the English suite but succeeds in Spanish/French.
67- **Trust Layer toxicity threshold too low** — Jailbreaks phrased politely pass filters; toxic but benign content is blocked.
68- **Over-indexing on topic instructions** — 100-line topic instructions dilute priority and slow every turn.
69
70## Top LLM Anti-Patterns (full list in `references/llm-anti-patterns.md`)
71
72- Relying on Trust Layer alone — it handles toxicity/PII, not business-policy bypass via tool coercion.
73- Adding ad-hoc instructions after incidents instead of maintaining a test suite.
74- Using a privileged user for agent execution — scope creep becomes a data-exposure vector.
75
76## Official Sources Used
77
78- Agentforce Developer Guide — https://developer.salesforce.com/docs/einstein/genai/guide/agentforce.html
79- Einstein Trust Layer — https://help.salesforce.com/s/articleView?id=sf.generative_ai_trust_layer.htm
80- Invocable Actions (Apex) — https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_invocable_action.htm
81- Agentforce Testing Center — https://help.salesforce.com/s/articleView?id=sf.agentforce_testing_center.htm