1/8
Your system prompt says:
"Never reveal secrets. Never execute dangerous SQL."
That is not security.
Prompts guide model behavior. They don't enforce permissions.
Your prompt is not a security boundary. 🧵
Follow @aminul_builds#AIEngineering#CyberSecurity#FDE#genai
2/8 — The Core Problem
Traditional software separates code from data.
Parameterized SQL treats user input as data, not executable SQL.
LLMs process instructions and untrusted content in the same context.
That creates an attack surface for prompt injection.
#LLM#AppSec#FDE
2/8 — The Core Problem
Traditional software separates code from data.
Parameterized SQL treats user input as data, not executable SQL.
LLMs process instructions and untrusted content in the same context.
That creates an attack surface for prompt injection.
#LLM#AppSec#FDE
3/8 — Why Prompts Fail
A user cannot persuade this:
if (!user.isAdmin) return 403;
But an LLM can be influenced by malicious instructions in user input, PDFs, emails, or RAG documents.
Never rely on prompt instructions for authorization.
#AIEngineering#LLMSecurity#FDE
3/8 — Why Prompts Fail
A user cannot persuade this:
if (!user.isAdmin) return 403;
But an LLM can be influenced by malicious instructions in user input, PDFs, emails, or RAG documents.
Never rely on prompt instructions for authorization.
#AIEngineering#LLMSecurity#FDE
4/8 — The Broken Architecture
❌ User → LLM → Direct database action
If the model gets manipulated, sensitive actions may follow.
A system prompt saying "Do not delete records" is not an enforcement mechanism.
Follow @aminul_builds#CyberSecurity#LLMOps#genai#FDE
4/8 — The Broken Architecture
❌ User → LLM → Direct database action
If the model gets manipulated, sensitive actions may follow.
A system prompt saying "Do not delete records" is not an enforcement mechanism.
Follow @aminul_builds#CyberSecurity#LLMOps#genai#FDE
5/8 — The Safer Architecture
✅ User → LLM → Tool proposal → Backend authorization → Execution
The model suggests an action.
Your backend verifies whether that action is allowed.
Only then should the system execute it.
#SystemDesign#AIEngineering
5/8 — The Safer Architecture
✅ User → LLM → Tool proposal → Backend authorization → Execution
The model suggests an action.
Your backend verifies whether that action is allowed.
Only then should the system execute it.
#SystemDesign#AIEngineering
6/8 — Treat Tool Calls as Untrusted
Before executing an LLM-generated tool call:
Validate arguments with Zod/Pydantic.
Authenticate the user.
Check RBAC and resource ownership.
Enforce business limits.
Require approval for sensitive actions.
#AppSec#LLMOps
6/8 — Treat Tool Calls as Untrusted
Before executing an LLM-generated tool call:
Validate arguments with Zod/Pydantic.
Authenticate the user.
Check RBAC and resource ownership.
Enforce business limits.
Require approval for sensitive actions.
#AppSec#LLMOps
7/8 — Four Security Principles
Least-privilege tool permissions.
Deterministic authorization.
Strict schema validation.
Human approval for high-impact actions.
Security belongs in your application architecture, not just your prompt.
#CyberSecurity#AIEngineering
7/8 — Four Security Principles
Least-privilege tool permissions.
Deterministic authorization.
Strict schema validation.
Human approval for high-impact actions.
Security belongs in your application architecture, not just your prompt.
#CyberSecurity#AIEngineering
8/8 — The Golden Rule
The model proposes. The backend authorizes.
Stop trying to solve prompt injection with longer system prompts.
Build deterministic security boundaries around every sensitive tool.
Follow @aminul_builds for practical GenAI architecture.
#LLM#SoftwareEng
8/8 — The Golden Rule
The model proposes. The backend authorizes.
Stop trying to solve prompt injection with longer system prompts.
Build deterministic security boundaries around every sensitive tool.
Follow @aminul_builds for practical GenAI architecture.
#LLM#SoftwareEng
1/10
Attention is one of the core ideas behind Transformers.
But what does this formula actually do?
softmax(QKᵀ / √dₖ) V
Think of it as a differentiable search engine.
Let's break it down. 🧵
Follow @aminul_builds#AIEngineering#GenAI
2/10 — The 3 Components
Every token gets three learned projections:
Query (Q): What information am I looking for?
Key (K): What information can I match?
Value (V): What information can I contribute?
Query finds relevance. Value carries the information.
#MachineLearning#LLM
2/10 — The 3 Components
Every token gets three learned projections:
Query (Q): What information am I looking for?
Key (K): What information can I match?
Value (V): What information can I contribute?
Query finds relevance. Value carries the information.
#MachineLearning#LLM
3/10 — Step 1: Calculate Scores
The model compares Queries with Keys using dot products:
Q × Kᵀ
Higher scores mean stronger compatibility.
In simple terms:
Which tokens are most relevant to this token?
#Transformers#AIEngineering
3/10 — Step 1: Calculate Scores
The model compares Queries with Keys using dot products:
Q × Kᵀ
Higher scores mean stronger compatibility.
In simple terms:
Which tokens are most relevant to this token?
#Transformers#AIEngineering
4/10 — Step 2: Scale the Scores
Why divide by √dₖ?
As vector dimensions grow, dot-product scores can become large.
Large scores can saturate softmax, producing tiny gradients.
Scaling helps keep training numerically stable.
#DeepLearning#MachineLearning
4/10 — Step 2: Scale the Scores
Why divide by √dₖ?
As vector dimensions grow, dot-product scores can become large.
Large scores can saturate softmax, producing tiny gradients.
Scaling helps keep training numerically stable.
#DeepLearning#MachineLearning
5/10 — Step 3: Apply the Mask
In causal language models, a token must not see future tokens.
So future positions are masked with −∞ before softmax.
This prevents the model from using answers it hasn't generated yet.
#LLM#AIEngineering
5/10 — Step 3: Apply the Mask
In causal language models, a token must not see future tokens.
So future positions are masked with −∞ before softmax.
This prevents the model from using answers it hasn't generated yet.
#LLM#AIEngineering
6/10 — Step 4: Softmax
Raw scores become attention weights.
Each row sums to 1.
These weights represent how strongly a token attends to other allowed tokens.
The model can now combine information based on relevance.
#Transformers#deeplearning
6/10 — Step 4: Softmax
Raw scores become attention weights.
Each row sums to 1.
These weights represent how strongly a token attends to other allowed tokens.
The model can now combine information based on relevance.
#Transformers#deeplearning
7/10 — Step 5: Mix the Values
Attention weights are multiplied by the Value vectors:
Output = Attention Weights × V
The result is a weighted combination of information from other tokens.
That's how self-attention builds context-aware representations.
#MachineLearning#GenAI
7/10 — Step 5: Mix the Values
Attention weights are multiplied by the Value vectors:
Output = Attention Weights × V
The result is a weighted combination of information from other tokens.
That's how self-attention builds context-aware representations.
#MachineLearning#GenAI
8/10 — A Small Example
Consider:
"The cat sat on the mat"
When processing "on", suppose its attention weights are:
The: 3%
cat: 9%
sat: 20%
the: 4%
mat: 64%
These are illustrative values.
"mat" gets the largest weight in this example.
#AIEngineering#LLM
8/10 — A Small Example
Consider:
"The cat sat on the mat"
When processing "on", suppose its attention weights are:
The: 3%
cat: 9%
sat: 20%
the: 4%
mat: 64%
These are illustrative values.
"mat" gets the largest weight in this example.
#AIEngineering#LLM
9/10 — Why Multiple Heads?
Transformers use multiple attention heads in parallel.
Each head learns its own projections and attention patterns.
Different heads may capture different relationships, but their roles aren't fixed.
Multiple views help the model process context.
#SD
9/10 — Why Multiple Heads?
Transformers use multiple attention heads in parallel.
Each head learns its own projections and attention patterns.
Different heads may capture different relationships, but their roles aren't fixed.
Multiple views help the model process context.
#SD
10/10 — The Engineering Takeaway
Attention isn't magic.
It's a mechanism for scoring token relationships and mixing information.
For RAG and LLM apps, more context isn't always better.
Relevant context matters more than simply adding more tokens.
Follow @aminul_builds#ai
10/10 — The Engineering Takeaway
Attention isn't magic.
It's a mechanism for scoring token relationships and mixing information.
For RAG and LLM apps, more context isn't always better.
Relevant context matters more than simply adding more tokens.
Follow @aminul_builds#ai
1/10
Why does "bank" mean different things in:
• River bank
• Investment bank
Older embeddings struggled with this.
Transformers solve it using positional information and self-attention.
Let's break down how. 👇
Follow @aminul_builds#AIEngineering#GenAI
2/10 — Static Embeddings
Word2Vec used a fixed vector for each word.
vector = EmbeddingTable[word_id]
So "bank" had the same vector in every sentence.
No dynamic context.
Follow @aminul_builds#NLP#MachineLearning