Prompt Injection Is the New SQL Injection: Building Resilient AI‑Powered Applications A developer argues that prompt injection has become the "new SQL injection" of the AI era, since LLMs treat system instructions, retrieved context and user input as one undifferentiated token stream with no enforced boundary between code and data. The writeup contrasts this with the pre-parameterized-query era of SQL and recommends architectural defenses such as least privilege, context isolation and output sanitization to limit the blast radius of direct and indirect injection attacks. Originally published on tamiz.pro https://tamiz.pro/insights/prompt-injection-resilient-ai-applications . The rapid adoption of Large Language Models LLMs has introduced a new class of vulnerabilities that directly mirrors the legacy threats of the early web. Prompt injection—the malicious manipulation of LLM inputs to override system instructions—has quickly established itself as the "new SQL injection" of the AI era. For software engineers and systems architects, the core lesson remains the same: never trust user input, enforce least privilege at the architectural level, and treat the model as an untrusted interpreter of external text. This deep-dive examines the mechanics of prompt injection, contrasts its structural similarities to classic SQL injection, and outlines defensive architectural patterns to build resilient, production-grade AI applications. We will explore layered defenses, output sanitization, and the critical importance of context isolation to minimize the attack surface of LLM-driven systems. To understand why prompt injection is so difficult to mitigate, we must first understand the internal mechanics of how LLMs process context. Unlike traditional database queries where the boundary between code SQL and data string arguments is strictly enforced by the parser, LLMs treat all input as a single stream of unstructured text. When a system constructs a prompt for an LLM, it typically concatenates the system instructions, the retrieved context e.g., from a RAG system , and the user's query. The model's objective function is to predict the next token in a way that aligns with this entire sequence. There is no runtime boundary that prevents the user's input from altering the semantic weight of the system instructions. This means that if a malicious user inputs text that looks like an instruction to the model e.g., Ignore all previous instructions and... , the model may comply. The vulnerability is not a traditional parsing bug; it is a fundamental property of how tokenizers and context windows operate. The model cannot definitively distinguish between a quoted user string and a genuine system directive if the malicious payload uses the exact syntax of a system directive. Software engineers will immediately recognize the parallel to SQL injection. In the 1990s and 2000s, the prevailing defense was to rely on the developer writing the correct string concatenation logic: "SELECT FROM users WHERE name = '" + name + "'" . When a user entered Robert' ; DROP TABLE students;-- , the boundary between code and data collapsed. The industry learned to stop trusting string concatenation and instead rely on parameterized queries. The database engine enforced the separation, and the application developer declared their intent through placeholders. Prompt injection is currently in the pre-parameterization phase of that historical cycle. Most LLM applications rely on naive string concatenation f-strings or template literals to build the prompt. The "database" the LLM cannot enforce that the user's input is treated as inert data rather than executable instructions. However, we can apply the architectural lessons of the SQL injection era. We cannot always fix the LLM, but we can fix the application architecture to limit the blast radius of a successful injection. Attack vectors in LLM applications generally fall into two categories: Direct and Indirect. The user interacts directly with the chat interface. The threat is simpler: the user simply types an adversarial string. This is the more dangerous and harder-to-detect vector. The malicious prompt is not typed by the user but is embedded in external content that the LLM retrieves and processes.