ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

ChatGPT & LLM AI Engineering Guide• 6 min read

Core Prompt Engineering Techniques

Learn the fundamental anatomy of a high-precision prompt: Persona, Context, Task, Constraints, and Output Format.

The Anatomy of an Industry-Grade Prompt

Vague prompts generate generic, hallucinated, or unhelpful answers. High-performing prompts follow structured frameworks: Role, Task, Context, Constraints, and Output Specification.

Role / Persona: Instructs the model on its expertise level, perspective, and tone of voice (e.g., "Senior Security Engineer").
Task: The precise action requested with explicit verbs (e.g., "Analyze", "Extract", "Refactor").
Context: Necessary reference documentation, schemas, or background info.
Constraints: Guardrails that restrict output format, character length, or forbidden behaviors.
Output Format: Demanding JSON, markdown tables, or specific schemas.
Structured Prompt Framework
const prompt = `
You are a Principal Security Engineer (ROLE).
Analyze the following Node.js authentication middleware snippet for timing attacks and SQL injection (TASK).

Code to audit:
"""
app.post('/login', async (req, res) => {
  const user = await db.query('SELECT * FROM users WHERE email = ' + req.body.email);
  if (user && user.password === req.body.password) return res.send('OK');
});
"""

Constraints:
1. Provide a table of identified vulnerabilities with severity (High/Med/Low).
2. Rewrite the code using parameterized queries and crypto.timingSafeEqual.
3. Respond in concise markdown format without conversational filler.
`;
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which prompting component establishes the expertise, tone, and perspective of the language model?