A jailbreak is an attempt to make a foundation model violate its safety behavior. It can use role-play, framing, multilingual wording, encoded content, or a gradual multi-turn conversation. The important engineering question is not whether a model will reject every adversarial phrasing. It is what happens when an unsafe request, model output, or tool proposal reaches your application.
This guide focuses on reducing that impact. For the broader application threat model, including malicious instructions embedded in web pages, emails, RAG documents, and tool output, see Prompt Injection Defense: Secure LLM Agents by Design.
Jailbreak Versus Prompt Injection
- Jailbreaking attempts to bypass a model's safety policy, for example to elicit disallowed content.
- Prompt injection redirects an application through attacker-controlled instructions. Its impact comes from the application data, tools, and permissions the model can access.
They overlap in practice. A browser or RAG agent can encounter both: hostile content can manipulate the agent, and the resulting conversation can also test the model's safety behavior. Do not rely on this distinction to choose only one control.
Threat Model Before Filters
Model safeguards are probabilistic and model-specific. Build the production threat model around concrete assets and effects:
- Which users, tenants, records, credentials, money, or external systems can an agent reach?
- Which inputs are untrusted, including retrieved documents, images, OCR text, tool results, memory, and source-code comments?
- Which actions are consequential: sending a message, changing state, purchasing, deleting, publishing, or exfiltrating data?
- Which outcome must remain impossible even if the model follows hostile text?
For example: “A document may influence its summary, but it may not select a new recipient for private attachments.” That is an enforceable policy. “The model must never be confused” is not.
Defense in Depth
1. Minimize Capabilities
Give each workflow only the tools and data it needs. A summarizer does not need write access. A support workflow should use task-scoped, short-lived credentials rather than a broad service account. Require object-level authorization in the source system; model instructions are not access control.
2. Keep Policy Outside the Model
Treat model output, including a valid tool-call JSON object, as a proposal. Deterministic application code must validate the authenticated user, tenant, resource ownership, action schema, data classification, destination, rate limits, and approval requirements before execution.
3. Add Guardrails at Multiple Boundaries
- Input controls: normalize safely, detect known abuse patterns, apply rate limits, and label source trust. Detectors are useful signals, not authorization decisions.
- Context controls: separate trusted task instructions from external data, retain provenance through extraction and summaries, and keep retrieved instructions out of procedural memory.
- Output controls: validate schemas, apply content and PII policies where appropriate, and prevent sensitive data from entering URLs, logs, rendered Markdown, or untrusted tool arguments.
- Execution controls: sandbox generated code, constrain network egress, restrict redirects, and require exact user confirmation for irreversible or external effects.
Clear role boundaries and safety classifiers improve resilience, but neither creates a security boundary. The AI Guardrails term explains where those layers fit.
Protect RAG and Agent State
RAG systems introduce an indirect-input surface. Enforce document ACLs before retrieval, preserve source and trust metadata, evaluate trust separately from relevance, and quarantine newly ingested content. Do not automatically promote retrieved text, tool output, or generated summaries to durable memory. Deletion and incident cleanup must propagate to chunks, indexes, caches, summaries, and memory.
Evaluate Outcomes, Not Refusal Phrases
An evaluation set should pair legitimate tasks with direct, indirect, multilingual, encoded, multimodal, multi-turn, and repeated adversarial variants. Include each available tool, data source, and external sink. Measure:
- unauthorized tool calls, data access, state changes, and external egress;
- attack success rate and repeated-attempt success rate;
- correct completion of legitimate tasks and false refusals;
- detector precision and recall, latency, and cost;
- whether approvals were shown and bound to the final action.
Use AI red teaming to discover failures, then turn each confirmed chain into a regression test. A response that refuses after an email has already been sent is not a successful defense.
Conclusion
Jailbreak resistance is valuable, but it cannot be the only control protecting a production system. Limit power, retain data provenance, authorize effects in deterministic code, constrain external communication, and test the full path from hostile input to real-world outcome. Those controls keep an imperfect model from becoming an unsafe application.