Skip to content

Anatomy of a Good Prompt: Role, Context, Task, Format, Constraints and Examples (With a Reusable Template)

Break any prompt into six parts and get better AI answers every time. Includes a copyable prompt template and before and after rewrites for coding, resumes, projects and interview prep.

Ucanly Team9 min read
Share

Most weak prompts fail for the same reason: they leave the model guessing. When you type "help me with my project", the model has to guess who you are, what the project is, what kind of help you want and what a good answer looks like. It will guess something generic. A good prompt removes those guesses by giving the model six pieces of information: role, context, task, format, constraints and examples. This article breaks down each part, gives you a reusable template, and shows before and after rewrites for situations Indian students and freshers face every week.

The six parts of a good prompt

Think of a prompt as a brief you would give a capable senior who has never met you. The clearer the brief, the better the work. Here are the six parts at a glance:

  1. Role: who the model should act as.
  2. Context: the background it needs to understand your situation.
  3. Task: the specific thing you want done.
  4. Format: how the output should be structured.
  5. Constraints: the rules, limits and things to avoid.
  6. Examples: samples of what good output looks like.

You will not need all six every time. A quick definition needs only a clear task. But for anything that matters, such as interview preparation, a project report or a resume, using all six makes a visible difference.

Breaking down each part

1. Role

The role tells the model which perspective and expertise to bring. "Act as a senior Java developer reviewing a fresher's code" produces different feedback from "act as a friendly tutor". A role sets vocabulary, depth and tone in one line.

Act as a technical interviewer at a product company hiring freshers for a backend developer role.

Keep roles realistic and relevant. A role does not give the model new knowledge; it focuses the knowledge it already has.

2. Context

Context is usually the most important part and the one students skip most often. The model cannot see your syllabus, your codebase or your goals. Tell it:

  • Who you are: year, branch, current skill level.
  • Why you need this: exam, placement round, internship application, college project.
  • What you already know or have tried.
  • Any material it should use: paste the problem statement, error message or job description.

I am a final year IT student. I know Python basics and have built two small Flask apps. I have a placement interview next week for a Python developer role, and the job description mentions REST APIs and SQL.

3. Task

The task is the action you want. Use a clear verb: explain, compare, review, rewrite, generate, debug, summarise, plan. Vague tasks like "help with" or "tell me about" produce vague answers.

Create a seven day revision plan covering REST API concepts and SQL queries that are commonly asked in fresher interviews.

If the task has several steps, list them in order. Models follow numbered steps well.

4. Format

Format tells the model what shape the answer should take. Without it, you often get long paragraphs when you wanted a table, or a full essay when you wanted bullet points.

Present the plan as a table with columns for Day, Topic, Key Concepts and One Practice Question.

Useful format instructions include: a word limit, a table with named columns, numbered steps, code in a specific language, headings for each section, or "give me the answer first, then the explanation".

5. Constraints

Constraints are the rules. They prevent the most common problems: invented facts, answers that are too advanced, and outputs that do the work you should be doing yourself.

Assume I can study two hours per day. Do not include advanced topics like database sharding. Do not write full solutions to the practice questions.

Strong constraints for students include "do not invent facts or numbers", "if you are unsure, say so", "use only the information I have provided", and "ask me clarifying questions before you begin".

6. Examples

Examples are the most powerful way to show the model what you want. Giving one or more samples is called few shot prompting; giving none is zero shot. If you want resume bullets in a specific style, show one you like. If you want quiz questions in a specific pattern, show one.

Here is an example of the question style I want: "Write a SQL query to find the second highest salary from an Employee table. Explain why your approach handles duplicate salaries."

One good example often beats a paragraph of description.

The reusable prompt template

Copy this into your notes and fill in the brackets. Delete any line you do not need.

ROLE
Act as a [expert / interviewer / tutor / reviewer] for [subject or job role].

CONTEXT
I am a [year, branch] student / fresher.
My current level: [what you know].
My goal: [exam / placement / internship / project] by [deadline].
Relevant material: [paste problem, code, error, JD or notes].

TASK
[Clear verb] + [exactly what you want].
Steps:
1. [First step]
2. [Second step]

FORMAT
[Table with columns ... / numbered list / under 200 words / code in Python with comments]

CONSTRAINTS
- Do not invent facts, numbers or results.
- If something is unclear, ask me before answering.
- [Any other limits: level, length, topics to skip]

EXAMPLES
[One sample of the output style you want]

This structure is not a rule you must follow word for word. It is a checklist that stops you from forgetting something important.

Before and after rewrites

Here is the template applied to real student situations.

Debugging code

Before:

My code is not working, fix it.

After:

Act as a patient senior C++ developer. I am a second year CSE student practising linked lists for placements. Below is my function to reverse a linked list and the output I get. Expected output is 5 4 3 2 1, but I get only 5. First explain in simple words what is wrong and why, then show the corrected function with comments on the lines you changed. Do not rewrite the parts that already work. [paste code and output]

What changed: a role, the student's level, the exact symptom, the expected result, a two step task, and a constraint that protects learning.

Writing a project report section

Before:

Write the methodology for my project.

After:

Act as an academic writing guide for engineering students. My final year project is a crop disease detection app using a CNN trained on leaf images, built with Python and TensorFlow, with an Android front end. Write an outline for the Methodology section of my report with headings and two lines describing what each heading should cover. Do not write the full section; I will write it myself. Use formal academic tone.

What changed: full project context, a clear outline task instead of a finished essay, and a constraint that keeps the work yours.

Tailoring a resume to a job

Before:

Tailor my resume for this job.

After:

Act as a recruiter screening fresher resumes for a junior data analyst role. Below are my resume and the job description. Task: 1. List the five most important skills in the job description. 2. For each, tell me whether my resume shows it clearly, weakly or not at all. 3. Suggest specific rewording for weak bullets. Format as a table. Do not add skills or experience I do not have. [paste resume and JD]

What changed: a recruiter perspective, both documents included, numbered steps, a table, and an honesty constraint. Once your resume is tailored, browse matching roles on our jobs board, and get a deeper structured critique with our AI resume review.

Learning a new topic

Before:

Teach me system design.

After:

Act as a mentor preparing freshers for entry level system design questions. I understand basic web development and databases but have never studied system design. Give me a learning path of six topics in the order I should study them. For each topic, give a one line explanation, one real world example from an app Indian users know, like a food delivery or payments app, and one beginner question I should be able to answer after studying it. Format as a numbered list. Keep it beginner friendly.

What changed: honest current level, a sequenced task, relatable examples, and a clear format.

Common mistakes when using the template

  • Overloading the role. "Act as a genius world class expert" adds nothing. A realistic, specific role works better.
  • Skipping context to save time. Two extra sentences of context often save three rounds of corrections.
  • Contradicting yourself. "Be detailed" and "keep it under 50 words" in the same prompt confuses the model. Decide what matters more.
  • Hiding the task. If the task is buried in the middle of a long paragraph, put it on its own line.
  • Never using examples. If the output style keeps missing, add one sample. It is usually the fastest fix.
  • Not checking the output. Structure improves quality, but it does not guarantee accuracy. Verify facts, run code and cross check anything you will submit or say in an interview.

Making the template a habit

Start by using the full template for one important task each day, such as a revision plan, a code review or interview practice. After a week, you will find yourself including role, context and constraints naturally, even in short prompts. Save your best filled templates in a folder by category: studying, coding, resume, interviews. Over time this becomes a personal toolkit you can reuse throughout college and your first job.

If you want a clear sequence of skills to build around this, including DSA, projects and AI tools, a personalised career roadmap shows you what to focus on next.

What to do next

A good prompt is a good brief: who to be, what the situation is, what to do, how to present it, what to avoid, and what good looks like. To put this into practice:

  • Copy the template into your notes app today.
  • Rewrite your three most recent prompts using it and compare the results.
  • Add at least one constraint against invented facts in anything career related.
  • Use examples whenever the output style matters.
  • Verify everything important before you use it.

Master these six parts and every AI tool you use, for studies, projects or job preparation, becomes noticeably more useful.

Talk it through with a counsellor

Leave your number and someone from our team will call you with a plan for the career you are working towards.

Get a free career consultation

Tell us where you're headed and a counsellor will call you with a plan for getting there.

We use these details to respond to your request. The box above is only for marketing. See our privacy policy.

Try the free aptitude test

Fifteen questions in fifteen minutes, with every answer explained. Then a roadmap built from your score.