By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You're building an LLM application and need to ship it without handing attackers a foothold. The problem: LLM models cannot reliably distinguish instructions from data. Any text they read—user messages, web pages, PDFs, tool outputs—might contain hidden commands. Prompt injection has no complete technical fix, so your design must assume the model will be tricked and limit the damage instead.
Treat the model's output exactly like user input. It is not trusted. Once the model generates text, that text can be weaponized if you pass it directly into a SQL query, shell command, HTML template, or another service without validation.
UNTRUSTED TRUSTED BOUNDARY POWER
user input ─┐
web pages ├─▶ LLM ─▶ output ─▶ allow-list ─▶ human ─▶ tools, DBs,
documents │ filter + permission approval email
tool results ─┘ (treat output as untrusted) (risky)
capability limits are the real defenceThe diagram shows the flow: untrusted sources feed the model, the model produces output, and that output must pass through a filter before it reaches anything with power. The real defense is not hoping the model refuses a malicious instruction. It is capability limits—shrinking what the agent is allowed to do in the first place.
OWASP published a top 10 list for LLM security in 2025. Use it as a design checklist, not a compliance box. Each item is a question you must answer before launch.
Several concrete patterns emerge from the top 10. Apply least privilege to tools: read-only by default, scoped credentials, per-user identity instead of one powerful service account. Human approval gates irreversible or high-value actions. Deterministic policy lives outside the model—a prompt saying 'never do X' is a suggestion, not a control.
Never store secrets in prompts. Use a credential vault and inject tokens at the tool layer. Enforce tenant separation with namespaced memory, filtered retrieval, and no shared caches for private answers. Log and review: maintain an audit trail of prompts, tool calls and decisions, with sensitive fields redacted.
Before launch, red-team your own app. Try to break it with injected documents and adversarial user input. The goal is to find exploits you control, not ones your users find in production.
If you can only do one thing: shrink what the agent is allowed to do. A tricked model with no dangerous tools is an annoyance; a tricked model with admin access is an incident.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.