Nearby lessons

3 of 49

Prompt Engineering - The Prompt Formula

The Prompt Formula

The prompt formula is a structured way of writing any prompt. It has five parts and gives you clear direction plus full control over AI's output:

PartWhat it meansExample
RoleWho AI should act likeAct as a teacher, HR, interviewer...
TaskWhat AI should doExplain, write, list, compare...
ContextBackground information / for whomfor beginners, for freshers, for my manager...
ConstraintsRules / limitsno jokes, 5 bullet points, polite and short...
Output formatHow the answer should looktable, bullet points, email, 100 words...
In simple words: The prompt formula is the heart of prompt engineering. Role gives direction, context gives clarity, constraints control behavior, and output format gives shape.

The tailor example shows why structure matters:

  • "Stitch shirt" → creates confusion.
  • "Stitch a white cotton shirt, full sleeve, size 40, office use" → gives the tailor everything needed.

Same tailor — the structured instruction made the difference.

The Escalation Ladder — One Prompt, Six Levels

Here is one prompt evolving level by level. Each step adds one part of the formula — Role, Task, Context, Constraints, Output format — and the output becomes more predictable with every level.

  • STEP 1 → 2: +Role gives direction.
  • STEP 2 → 3: +Task says what to do.
  • STEP 3 → 4: +Context adds who it is for.
  • STEP 4 → 5: +Constraints add rules.
  • STEP 5 → 6: +Format locks the shape of the answer.
Trainer's Note: Step 1 is a casual question; Step 6 is a complete instruction. Each small addition moved the output from random to professional. This is the difference between a casual user and a prompt engineer — the casual user types once, the engineer builds the prompt step by step.
Example02
Prompt PreviewChatGPT-style
STEP 1 (RAW): Explain Python loops STEP 2 (+ROLE): Act as a school teacher. Explain Python loops STEP 3 (+TASK): Act as a school teacher. Explain the for loop with one daily-life example STEP 4 (+CONTEXT): Act as a school teacher. Explain the for loop with one daily-life example for a beginner student STEP 5 (+CONSTRAINTS): Act as a school teacher. Explain the for loop with one daily-life example for a beginner student. Use simple Indian English STEP 6 (+FORMAT): Act as a school teacher. Explain the for loop with one daily-life example for a beginner student. Use simple Indian English. Format: heading + 2-line explanation + one example
Copy the prompt and paste it into ChatGPT, Gemini, or Claude to try it.

Prompt Formula in Action — Interviewer Example

One more example for interview practice:

Trainer's Note: You do not need to write the words ROLE / TASK / CONTEXT in your prompt. Just include the idea behind each part and AI automatically understands the structure.
Example03
Prompt PreviewChatGPT-style
Act as an interviewer. (ROLE) Ask me 5 Java interview questions (TASK) for a fresher. (CONTEXT) Wait for my answer after each question. (CONSTRAINTS) Give each question as Q1, Q2, ... (OUTPUT)
Copy the prompt and paste it into ChatGPT, Gemini, or Claude to try it.

Without Formula vs With Formula

Without FormulaWith Formula
Random outputStructured output
Less clarityHigh clarity
Less controlFull control
General answersTargeted answers
Wastes timeSaves time

Real-World Use Cases

  • Student — notes, explanations, study plans with a clear role and format.
  • Employee — emails, reports, task planning with constraints.
  • Business — marketing content, captions, ideas with a defined output format.
📝 Key Takeaways
  • Prompt clarity = specific + complete.
  • Vague or incomplete prompts make AI guess; complete prompts give strong output.
  • The prompt formula has 5 parts: Role, Task, Context, Constraints, Output format.
  • Build prompts level by level — each level adds one part of the formula.
  • Role gives direction, context gives clarity, constraints give control.
  • The tailor example: a structured instruction gives a perfect result.
  • Apply the formula to every prompt and AI output becomes professional.

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5