DEV Community

Cover image for Prompt Engineering for Beginners (Part 2): The Anatomy of a Good Prompt
Darshan kunwar
Darshan kunwar

Posted on Edited on

Prompt Engineering for Beginners (Part 2): The Anatomy of a Good Prompt

Part 1 of our Prompt Engineering from Scratch series, we explored how AI generates answers, what tokens and context windows are, and why the way we communicate with AI matters.

We learned one important lesson:

Getting better results from AI isn't always about using a more powerful model. Sometimes, it's about giving clearer instructions.

But knowing that we should write better prompts is one thing.

How do we actually write them?

What information should we include? How specific should our instructions be? And how do we know whether our prompt is good enough?

That's exactly what we'll explore in Part 2.

We'll break down six useful components of a well-structured prompt, understand what each one does, and learn how to combine them using simple, real-life examples.

No complicated terminology. No programming knowledge required.

Let's get started.

In Part 2, we'll learn the six useful building blocks of a good prompt, how to combine them, and how to test whether our prompts are working.

And don't worry. You don't need any technical background.

Let's begin with something we all understand.

1. Why Isn't a Simple Prompt Always Enough?

Imagine you're asking a friend to help you write an email.

You say:

Write an email for me.

Your friend would probably have a few questions.

Who is the email for?

What is it about?

Should it sound formal or friendly?

How long should it be?

Without that information, your friend has to guess.

AI faces a similar problem.

A basic prompt

Let's say you type:

Write an email asking for leave.
Enter fullscreen mode Exit fullscreen mode

The AI might produce an email, but it doesn't know important details.

For example:

  • Who are you writing to?
  • Why do you need leave?
  • How many days do you need?
  • What tone should the email use?
  • Should the email be short or detailed?

Now let's make the prompt clearer.

A more detailed prompt

Write a professional email to my manager
requesting two days of leave.

I need leave on Monday and Tuesday
because of a family commitment.

Keep the email polite and under 120 words.

Include a subject line.
Enter fullscreen mode Exit fullscreen mode

This is much clearer.

You've given the AI the information it needs to create a more suitable response.

Does that guarantee the perfect email?

No.

But it reduces unnecessary guessing.

And that's the foundation of a good prompt.

A good prompt doesn't need complicated words. It needs clear instructions and enough relevant information.

2. The Six Building Blocks of a Good Prompt

When writing a prompt, there are six useful components you can think about.

These components help you explain what you need, how you want the task completed, and what the final answer should look like.

Component What it means Simple example
1. Role Who should the AI act as? Act as a helpful writing assistant.
2. Context What background information does it need? I'm writing to my manager about taking leave.
3. Examples Can you show what a good answer looks like? Here is an example of my writing style.
4. Task What exactly should it do? Write an email requesting two days of leave.
5. Constraints What rules should it follow? Keep it polite and under 120 words.
6. Output Format How should the answer be presented? Include a subject line and email body.

These six components provide a useful framework for writing clear prompts.

But here's something important: you don't need all six components every time.

For a simple question like:

What is the capital of Nepal?

A short prompt is perfectly fine.

For more complicated tasks, such as analyzing a document or writing a detailed report, additional information becomes more valuable.

The goal isn't to make every prompt longer.

The goal is to make every prompt clear enough for its purpose.

Now let's understand each component.

3. Component 1: Role - Who Should the AI Act As?

Imagine you're asking someone for advice.

If you need help preparing for an exam, you might ask a teacher.

If you need help improving your writing, you might ask an editor.

If you need help planning a trip, you might ask a travel guide.

Different roles suggest different ways of approaching a task.

You can use a similar idea when prompting AI.

Without a role

Help me improve this paragraph.
Enter fullscreen mode Exit fullscreen mode

With a role

Act as a friendly writing tutor.

Help me improve this paragraph using
simple English.

Explain what you changed and why.
Enter fullscreen mode Exit fullscreen mode

The second prompt gives the AI a clearer direction.

It suggests the type of assistance and explanation you want.

What is a system prompt?

You might hear the technical term system prompt.

In many AI applications, a system message contains higher-level instructions about how the assistant should behave.

For example, an application might instruct its AI assistant to use a particular language or follow certain rules.

However, when you type:

Act as a writing tutor.

into a normal chat, you're generally giving a role instruction as a user, not changing the application's actual system message.

You don't need to access system settings to use role-based prompting.

And a role doesn't give the model magical expertise or guarantee accurate answers.

It simply helps guide how the model approaches and presents the task.

When is this useful?

When you want a particular style of help, such as teaching, editing, planning, or reviewing.

4. Component 2: Context - Give the AI the Background Information

Imagine someone asks you:

What should I do?

You'd probably respond:

About what?

Without knowing the situation, it's difficult to give useful advice.

That's exactly why context matters.

Context is the background information that helps AI understand your situation or task.

Without context

Write an email requesting leave.
Enter fullscreen mode Exit fullscreen mode

With context

I'm an employee writing to my manager.

I need two days of leave on Monday
and Tuesday because of a family commitment.

My manager prefers short and
professional emails.
Enter fullscreen mode Exit fullscreen mode

Now the AI knows more about your situation.

It can use that information when preparing the email.

Another example

Imagine you're asking AI to recommend a laptop.

Basic prompt:

Recommend a laptop.
Enter fullscreen mode Exit fullscreen mode

Prompt with context:

I'm a university student.

I mainly use my laptop for online classes,
writing assignments, browsing, and watching videos.

My budget is around $600.

Recommend suitable laptops and explain
why they would fit my needs.
Enter fullscreen mode Exit fullscreen mode

The second prompt gives the model a much clearer picture of what you're looking for.

Can you provide too much context?

No.

More information isn't always better.

Imagine asking someone to help you choose a laptop, then telling them your entire life story.

Most of that information wouldn't help them.

The same applies to AI.

Provide the background details that matter for the task, and avoid including unnecessary personal or sensitive information.

Good context means relevant information, not simply more information.

5. Component 3: Examples - Show the AI What You Want

Sometimes it's easier to show someone what you want than to explain it.

Imagine you're asking a friend to design an invitation card.

Instead of describing every detail, you might show an example and say:

I want something similar to this.

AI can also use examples to understand the pattern, style, or structure you expect.

Without an example

Rewrite this message professionally.
Enter fullscreen mode Exit fullscreen mode

With an example

Rewrite my message in a professional
but friendly tone.

Example:

Original:
"Hey, send me the report."

Improved:
"Could you please send me the report
when you have a chance?"

Now rewrite this message:

"I need the meeting details."
Enter fullscreen mode Exit fullscreen mode

The example demonstrates the kind of change you want.

It shows the AI how to make a request sound more polite without changing its meaning.

A little technical detail: Zero-shot and Few-shot prompting

These are two terms you might encounter.

Zero-shot prompting means asking the AI to perform a task without providing examples.

For example:

Rewrite this sentence professionally:

"Send me the file."
Enter fullscreen mode Exit fullscreen mode

Few-shot prompting means providing one or more examples before asking the AI to perform the task.

For example:

Example 1:
"Send me the file."
→ "Could you please send me the file?"

Example 2:
"Call me tomorrow."
→ "Could you please call me tomorrow?"

Now rewrite:
"Give me the document."
Enter fullscreen mode Exit fullscreen mode

The examples help demonstrate the pattern.

However, examples aren't always necessary, and they don't automatically work better than clear instructions.

For simple tasks, a direct instruction may be enough.

We'll explore zero-shot and few-shot prompting in more detail in Part 3.

When should you use examples?

When you want a specific writing style, structure, classification, or repeated pattern.

6. Component 4: Task - Explain Exactly What You Need

This is one of the most important parts of a prompt.

The task tells the AI what it should actually do.

It sounds obvious, but vague tasks can lead to vague answers.

Example 1: Too vague

Help me with my resume.
Enter fullscreen mode Exit fullscreen mode

What kind of help?

Should the AI check grammar?

Improve the wording?

Shorten it?

Suggest missing sections?

Example 2: Clear task

Review my resume.

Identify unclear sentences and
suggest improvements.

Keep my existing experience and
achievements accurate.

Do not invent qualifications or
work experience.
Enter fullscreen mode Exit fullscreen mode

Now the AI knows what to focus on.

Another example

Basic:

Summarize this article.
Enter fullscreen mode Exit fullscreen mode

Clearer:

Summarize this article in five bullet points.

Focus on the main findings.

Explain any difficult terms in
simple English.
Enter fullscreen mode Exit fullscreen mode

Notice something?

We haven't used complicated technical language.

We've simply explained the task more clearly.

A useful habit: Before sending a prompt, ask yourself:

If someone who had never met me read this instruction, would they understand what I wanted them to do?

If the answer is no, you may need to make the task clearer.

7. Component 5: Constraints - Set Clear Rules and Limits

Now imagine you're asking someone to write a short speech.

You tell them:

Write a speech about teamwork.

They might write a ten-minute speech.

But you only have two minutes to speak.

The problem isn't necessarily the speech itself.

You forgot to explain the time limit.

That's where constraints come in.

Constraints are the rules or limitations you want the AI to follow.

They help make the output more suitable for your needs.

Example

Write a short speech about teamwork.

Rules:
- Use simple English.
- Keep it under 200 words.
- Include one everyday example.
- Avoid difficult technical terms.
- End with an encouraging message.
Enter fullscreen mode Exit fullscreen mode

Here, you've made your expectations much clearer.

Common types of constraints

Type Example
Length Keep it under 150 words.
Language Use simple English.
Tone Keep it polite and friendly.
Content Include three practical examples.
Restrictions Don't invent facts or statistics.
Structure Use short paragraphs.

Can constraints be too strict?

Yes.

If you add too many conflicting rules, the AI may struggle to follow them.

For example:

Explain this topic in detail using only ten words.

Those instructions work against each other.

So try to keep constraints realistic and relevant.

Remember: Constraints guide the AI, but they don't guarantee that every rule will always be followed.

That's why checking the final answer is still important.

8. Component 6: Output - Format Decide How the Answer Should Look

Imagine asking someone to organize your monthly expenses.

They could give you a long paragraph describing everything.

Or they could present a simple table.

Which would be easier to understand?

Usually, the table.

That's why output format matters.

Output format tells the AI how you want the final answer to be organized.

Without a format

Compare online learning and
classroom learning.
Enter fullscreen mode Exit fullscreen mode

The AI might produce several paragraphs.

With a format

Compare online learning and
classroom learning.

Present the comparison in a table.

Include:
- Cost
- Flexibility
- Interaction
- Advantages
- Disadvantages

Finish with a short summary.
Enter fullscreen mode Exit fullscreen mode

Now the structure is clear.

Common output formats

Format When it's useful
Paragraph Explanations and general writing
Bullet points Short summaries and quick ideas
Numbered steps Instructions and tutorials
Table Comparisons and organized information
Checklist Planning and reviewing tasks
Code Programming-related tasks
JSON When software needs a structured data format

A little technical detail: What is JSON?

JSON is a way to organize information using labels and values.

For example:

{
  "name": "Aarav",
  "age": 22,
  "city": "Kathmandu"
}
Enter fullscreen mode Exit fullscreen mode

You don't need to use JSON in everyday prompting.

It's mainly useful when applications or programs need information in a consistent structure.

For most beginners, requesting a paragraph, table, or list is enough.

The takeaway: Choosing the right output format can make an answer easier to read, check, and use.

9. Putting All Six Components Together

Now let's combine everything we've learned.

We'll use the same email example from the beginning.

Basic prompt

Write an email asking for leave.
Enter fullscreen mode Exit fullscreen mode

This might work, but it leaves several details unclear.

Structured prompt

ROLE:
Act as a professional writing assistant.

CONTEXT:
I'm an employee writing to my manager.
I need two days of leave on Monday and
Tuesday because of a family commitment.

EXAMPLE:
Use a polite and professional tone similar to:
"I would like to request your approval
for two days of leave."

TASK:
Write an email requesting the leave.

CONSTRAINTS:
- Keep it under 120 words.
- Use simple and professional language.
- Do not invent additional personal details.

OUTPUT FORMAT:
Include:
1. Subject line
2. Greeting
3. Email body
4. Closing
Enter fullscreen mode Exit fullscreen mode

This prompt gives the AI much clearer instructions.

What changed?

Component What we added
Role Professional writing assistant
Context Leave dates, reason, recipient
Examples Preferred writing tone
Task Write a leave-request email
Constraints Word limit, language, accuracy
Output Format Subject, greeting, body, closing

We haven't used any magic words.

We've simply organized our instructions.

Important: Do we always need six sections?

Absolutely not.

The same request could be written naturally in a few sentences:

Write a polite email to my manager requesting leave on Monday and Tuesday because of a family commitment. Keep it under 120 words, use simple professional English, and include a subject line.

That may be enough.

A well-structured prompt doesn't have to be long or complicated. It just needs to provide the information the task requires.

The six components are a guide, not a rule that every prompt must follow.

10. Basic vs. Structured Prompts: What's the Difference?

Let's compare a few everyday examples.

Situation Basic prompt More structured prompt
Learning Explain photosynthesis. Explain photosynthesis to a 12-year-old using simple English and one everyday example.
Writing Write a birthday message. Write a short, funny birthday message for my best friend. Keep it under 60 words.
Planning Make a study plan. Create a seven-day study plan for someone who can study two hours daily. Present it in a table.
Summarizing Summarize this document. Summarize the document in five bullet points, focusing on the main findings and important numbers.
Comparing Compare these phones. Compare these phones by price, battery, camera, and storage in a table.

Notice that the improved prompts aren't necessarily much longer.

They simply explain what matters.

Does a structured prompt always give a better answer?

Not necessarily.

For straightforward tasks, a simple prompt can work perfectly.

For complicated tasks, clear instructions often help.

And sometimes the model may still make mistakes despite having a well-written prompt.

That's why we need a way to test whether our changes actually improve the result.

11. A Real-World Example: Summarizing a Long Document

This example connects closely with my work testing AI models on real documents.

Imagine you upload a 50-page report and type:

Summarize this report.
Enter fullscreen mode Exit fullscreen mode

The AI might give you a useful general summary.

But suppose you actually need:

  • The report's main purpose
  • Important findings
  • Financial information
  • Major risks
  • Recommendations

Your original prompt didn't mention those expectations.

So you might have to ask several follow-up questions.

Now let's try a more structured approach.

ROLE:
Act as a research assistant.

CONTEXT:
I've uploaded a report that I need
to understand without reading every page.

TASK:
Summarize the report.

Include:
1. The main purpose of the report.
2. Five important findings.
3. Key financial figures, if available.
4. Major risks or limitations.
5. Important recommendations.

CONSTRAINTS:
- Use simple English.
- Keep the summary under 500 words.
- Do not invent missing information.
- Clearly mention if something is not found.

OUTPUT FORMAT:
Use headings and bullet points.

Where possible, include page references
so I can check the original information.
Enter fullscreen mode Exit fullscreen mode

This prompt gives the model a clearer structure.

It also makes the output easier to verify.

For example, if the AI reports a financial figure, you can check the page where that figure appears.

Of course, the model could still overlook information or provide an incorrect page reference.

A structured prompt improves clarity and makes verification easier. It doesn't eliminate the need to check important results.

12. For the Curious: How Developers Use Structured Prompts

If you're not from a technical background, you can skip this section.

Everything we've learned so far is enough to start improving your prompts.

But if you're curious about how developers use these ideas, here's a simple example.

Suppose a developer asks:

Write code to calculate the total price.
Enter fullscreen mode Exit fullscreen mode

The AI doesn't know the programming language, the calculation rules, or how to handle unusual inputs.

A clearer request might look like this:

ROLE:
Act as a Python programming assistant.

CONTEXT:
I'm building a small shopping application.

TASK:
Write a function that calculates the total
price of products in a shopping cart.

CONSTRAINTS:
- Each product has a price and quantity.
- Reject negative prices or quantities.
- Explain the calculation clearly.
- Include two example calculations.

OUTPUT FORMAT:
Return the Python code followed by
a short explanation.
Enter fullscreen mode Exit fullscreen mode

This follows the same six-component idea.

The only difference is the task.

A developer may also provide database information, existing code, error messages, or other technical details.

But the main principle remains the same:

Give the AI enough information to understand the task, and clearly explain how you want the answer.

Generated code still needs to be reviewed and tested before being used in a real application.

13. The Prompt Engineering Workflow

Now that we know how to build a prompt, what should we do if the first answer isn't good enough?

Should we rewrite everything?

Should we keep adding random instructions?

Not necessarily.

A better approach is to improve the prompt step by step.

Here's a simple workflow.

Step 1: Specify Decide What You Want

Before writing a prompt, identify:

  • Your goal
  • The information AI needs
  • The kind of answer you expect
  • Any important rules or limitations

For example:

I want a short explanation of climate change for a young student.

Step 2: Save Keep Your Original Prompt

Don't immediately replace your first prompt.

Keep a copy.

For example:

Version 1:

Explain climate change.
Enter fullscreen mode Exit fullscreen mode

This is your starting point.

You can compare future versions against it.

In technical settings, saving and tracking changes is sometimes called versioning.

But you don't need special software to do this.

A notebook or text document works perfectly.

Step 3: Test Change One Thing at a Time

Let's improve the prompt.

Version 2: Change the audience

Explain climate change to a 12-year-old.
Enter fullscreen mode Exit fullscreen mode

Now compare the answer with Version 1.

Did it become easier to understand?

Next, return to Version 1 and test a different change.

Version 3: Change the length

Explain climate change in 100 words.
Enter fullscreen mode Exit fullscreen mode

Now compare again.

This helps you understand whether specifying the audience or limiting the length made the answer more useful.

If you change five things at once, it becomes harder to identify which change helped.

AI responses can vary even when you use the same prompt, so repeat important tests before drawing strong conclusions.

Step 4: Improve Combine What Works

After comparing the results, you can combine useful instructions.

For example:

Explain climate change to a 12-year-old.

Use simple English.

Keep it under 100 words.

Include one everyday example.
Enter fullscreen mode Exit fullscreen mode

You now have a clearer prompt based on what you've learned.

Step 5: Reuse - Save Your Best Prompts

If a prompt works well for a task you repeat often, save it.

For example:

Explain [TOPIC] to [AUDIENCE].

Use simple language.

Keep the explanation under [WORD LIMIT].

Include [NUMBER] everyday examples.
Enter fullscreen mode Exit fullscreen mode

You can replace the words inside the brackets whenever you need to use the template again.

This is one of the practical benefits of prompt engineering.

Instead of starting from scratch every time, you build a collection of instructions that you can reuse and improve.

A simple workflow to remember

Specify → Save → Test → Improve → Reuse

In professional applications, teams may also track prompt versions, run repeated tests, compare results, and monitor performance after releasing an AI feature.

But for beginners, the same idea starts with something much simpler:

Keep your original prompt, change one thing, and check what happens.

14. Your Prompt Checklist

Before sending an important prompt, ask yourself:

  • [ ] Goal: Have I clearly explained what I want?
  • [ ] Context: Have I provided the necessary background information?
  • [ ] Role: Would specifying a role make the task clearer?
  • [ ] Examples: Would an example help show the result I expect?
  • [ ] Constraints: Have I mentioned important limits or rules?
  • [ ] Output Format: Have I explained how the answer should be presented?
  • [ ] Accuracy: Have I told the AI what to do if information is missing?
  • [ ] Verification: Can I check whether the result is correct?

You don't have to check every box for every question.

Use the ones that matter for your task.

15. Your 5-Minute Exercise: Build Your Own Prompt

Let's practice what we've learned.

Open your preferred AI chatbot.

We'll start with a simple request.

Step 1: Write a basic prompt

Make a study plan for me.
Enter fullscreen mode Exit fullscreen mode

Read the answer.

Is it suitable for your situation?

Does it know what subject you're studying?

Does it know how much time you have?

Step 2: Add context

I'm a student preparing for an exam
next week.

I can study for two hours every day.

Make a study plan for me.
Enter fullscreen mode Exit fullscreen mode

Compare the result with your first answer.

Step 3: Add useful constraints

I'm a student preparing for an exam
next week.

I can study for two hours every day.

Create a seven-day study plan.

Include short breaks.

Keep the activities realistic.
Enter fullscreen mode Exit fullscreen mode

Step 4: Specify the output format

I'm a student preparing for an exam
next week.

I can study for two hours every day.

Create a seven-day study plan.

Include short breaks.

Present the plan in a table with:
- Day
- Study topic
- Duration
- Activity
Enter fullscreen mode Exit fullscreen mode

Notice how the prompt becomes more specific.

The goal hasn't changed.

You've simply made your expectations clearer.

Step 5: Experiment

Now change only one part of the prompt.

For example:

  • Change the study time from two hours to one hour.
  • Or change the output format from a table to a checklist.
  • Or specify a particular subject.

Compare the results.

Ask yourself:

Which instruction changed the answer, and did that change make it more useful?

That's the habit I want you to develop throughout this series.

16. Quick Recap: The Six Components

Here's everything we've learned in one table.

Component Simple question to ask yourself
Role Who should the AI act as?
Context What does the AI need to know?
Examples Can I show what a good answer looks like?
Task What exactly do I want it to do?
Constraints What rules or limits matter?
Output Format How should the answer look?

And remember:

You don't need all six components for every prompt.

A simple question can have a simple prompt.

A complicated task may need more detail.

The purpose of prompt engineering isn't to make communication complicated.

It's to make it clearer.

What's Coming in Part 3?

In Part 3, we'll explore six useful prompting techniques:

  1. Zero-shot prompting: Asking AI to complete a task without examples.
  2. Few-shot prompting: Showing examples of the kind of answer you want.
  3. Chain-of-thought prompting: Approaches involving intermediate reasoning steps for more complicated tasks.
  4. Role-based prompting: Guiding AI through a particular role.
  5. Constraint-based prompting: Using clear rules and limitations.
  6. Meta-prompting: Using AI to help design or improve prompts.

We'll explain each one using practical examples and discuss when it might be useful.

Final Thoughts

In Part 1, we learned that language models don't automatically know what we expect from them.

Today, we learned how to communicate those expectations more clearly.

And here's the most important lesson:

A good prompt isn't measured by how long or complicated it is. It's measured by how clearly it communicates the task and how useful the result is.

You don't need to use special commands.

You don't need to memorize complicated terms.

And you certainly don't need a programming background.

Start with a simple prompt.

See what works.

Change one thing.

Compare the results.

And keep improving.

That's how you begin developing a prompt-engineering mindset.

One Question Before You Go

What's one task you regularly ask AI to help you with?

Writing emails? Studying? Summarizing documents? Planning your day?

Share your basic prompt in the comments, and let's see how we can improve it using the six components.

This is Part 2 of 6 in my "Prompt Engineering from Scratch" series. I work with and test open-source AI models on real documents, and I'm sharing what I learn along the way.

Follow the series if you'd like to understand AI and learn practical prompting techniques, one step at a time.

Further Reading

Top comments (0)