02. Crafting Effective Prompts: Context & Constraints
Explanation
Giving an AI a specific persona or role (Context) helps it narrow down its knowledge base and adopt a professional tone.
Constraints act as "guardrails" that prevent the model from becoming too verbose or straying off-topic during its response.
Explicitly stating the desired format (e.g., "3 bullet points") saves you from having to manually clean or parse the output later.
A well-crafted prompt should answer: What is the goal? Who am I? What are the rules? and How should the result look?
Iterating on these constraints is the "engineering" part of the process, finding the exact balance of freedom and restriction.
High-quality context reduces "hallucinations" by grounding the AI in a specific set of rules and a clear, defined identity.
Example
Act as a senior software engineer. Explain recursion to a 5-year-old. Do not use technical jargon. Length: 2 sentences.
Exercise Task
Create a prompt for an AI that acts as a Front-end UI/UX Critic. Ask it to review a landing page description. Constraints: Tone must be 'constructive but firm', and the output must be a bulleted list of exactly 3 points.
script.js
1
2
3
4
5
6
const systemRole = "Act as a...";
const task = "Review the following
landing page...";
const constraints = "- Tone: ...\n-
Format: ...";
const fullPrompt = `${systemRole}
\n\nTask: ${task}\n\nConstraints:\n$
{constraints}`;
console.log(fullPrompt);
Console
Click "Run" to execute your code...