DEV Community

Rahul Vijayvergiya
Rahul Vijayvergiya

Posted on • Originally published at rahulvijayvergiya.hashnode.dev

Prompt Engineering for Beginners: How to Talk to AI So It Gives Better Answers

Have You Ever Asked AI Something... and Got a Bad Answer?

Imagine you walk into a restaurant and simply say:

"Bring me food."

The waiter has no idea what you want.

Do you want pizza? Pasta? Vegetarian food? Something spicy? How many people are eating?

Now imagine you say:

"I'm vegetarian. I like spicy food. Please bring a medium-sized paneer pizza."

The waiter now understands exactly what you want.

Talking to AI works in a very similar way.

The more clearly you explain your request, the better the AI can understand what you need.

This is where Prompt Engineering comes in.


What is Prompt Engineering?

A prompt is simply the instruction or question you give to an AI.

Prompt Engineering is the practice of writing better prompts so the AI gives more useful, accurate, and consistent responses.

Think of it like giving instructions to a new employee.

If your instructions are vague, the result may not be what you expected.

If your instructions are clear, the chances of getting the right result become much higher.

You
  │
  │ Prompt
  ▼
+-------------+
|     AI      |
+-------------+
       │
       ▼
   Response
Enter fullscreen mode Exit fullscreen mode

Prompt Engineering isn't about using complicated words.

It's about communicating clearly.


Our Example Throughout This Article

Let's imagine Rahul has recently started learning Python.

He wants AI to help him study.

We'll improve his prompt step by step and see how each technique makes the answer better.


A Simple Prompt

Rahul starts with:

Explain Python.

The AI may answer with a general explanation.

That isn't wrong.

But Rahul is a beginner. He doesn't want a long technical explanation.

The prompt doesn't tell the AI enough about what he actually needs.


Prompt Structure

A good prompt usually answers a few simple questions.

  • What do you want?

  • Who is the answer for?

  • How should it be written?

  • Are there any restrictions?

Instead of writing:

Explain Python.

Rahul writes:

Explain Python for someone who knows JavaScript. Use simple English and include one real-life example.

Now the AI knows:

  • the topic

  • the audience

  • the writing style

  • what kind of example to include

Notice that Rahul didn't use any special AI trick.

He simply gave more context.


Role Prompting

Sometimes it helps to tell the AI what role to play.

For example:

Act as an experienced Python teacher. Explain Python to a beginner using simple language.

Now the AI answers from the perspective of a teacher instead of a researcher or documentation writer.

Common roles include:

  • Teacher

  • Software Architect

  • Technical Writer

  • Interviewer

  • Code Reviewer

  • Product Manager

The role doesn't change what the AI knows.

It mainly changes how it presents the answer.


Few-Shot Prompting

Sometimes explaining the format isn't enough.

Showing one or two examples helps the AI understand exactly what you want.

For example:

Question:
What is HTML?

Answer:
HTML is the structure of a webpage.

Now answer:

What is CSS?
Enter fullscreen mode Exit fullscreen mode

Because the AI saw one example, it is more likely to answer in the same style.

This technique is called Few-Shot Prompting because you provide a few examples before asking your real question.

Think of it like showing someone a sample before asking them to create something similar.


Output Formatting

Sometimes the answer is correct but difficult to read.

Instead of saying:

Explain Python.

Rahul writes:

Explain Python using:

  • A short definition

  • Three key features

  • One real-world example

  • A short summary

The information is the same.

But the response becomes much easier to understand.

You can ask the AI to produce:

  • Bullet points

  • Tables

  • Step-by-step guides

  • JSON

  • Markdown

  • HTML

  • CSV

  • Email format

The AI usually follows the structure you request.


Generation Parameters

So far, we've changed the prompt.

But AI models also have settings that affect how they generate responses.

These are called generation parameters.

Think of them as knobs you can adjust.

Most chat applications choose reasonable defaults, so beginners don't usually need to change them.

Still, it's useful to know what they do.


Temperature

Temperature controls how creative the AI becomes.

Low temperature makes the AI more focused and predictable.

High temperature allows more creativity and variation.

Think of it like this:

Low Temperature
      │
      ▼
More Predictable

High Temperature
      │
      ▼
More Creative
Enter fullscreen mode Exit fullscreen mode

Use a lower temperature for:

  • Documentation

  • Tutorials

  • Summaries

  • Technical explanations

Use a higher temperature for:

  • Stories

  • Brainstorming

  • Marketing ideas

  • Creative writing


Top-p

Top-p limits the AI to choosing from the most likely words until a probability threshold is reached.

Don't worry too much about the math.

The simple idea is:

The AI considers many possible next words.

Top-p reduces that list so it chooses only from the most likely options.

It helps balance creativity and accuracy.

For most beginners, the default value works well.


Top-k

Top-k is similar to Top-p.

Instead of looking at probabilities, it limits the AI to the top K most likely next words.

Smaller values make responses more focused.

Larger values allow more variety.

Again, most people rarely need to change this manually.


Max Tokens

Every AI response has a limit on how much it can generate.

That limit is controlled by Max Tokens.

If the limit is too small, the response may stop before finishing.

Imagine asking someone to explain a topic but allowing them to speak for only 30 seconds.

They probably won't finish.

Increasing Max Tokens simply allows the AI to generate a longer response.

It doesn't make the AI smarter.


Putting Everything Together

Let's improve Rahul's prompt one final time.

Instead of:

Explain Python.

He writes:

Act as an experienced programming teacher. Explain Python for someone who already knows JavaScript. Use simple English. Include one real-world example. Format the answer with headings, bullet points, and a short summary.

Notice how the prompt now provides:

  • A role

  • The audience

  • The task

  • The writing style

  • The output format

The AI now has much more context, so the response is likely to be far more useful.


Do You Need Perfect Prompts?

Not at all.

Many beginners think Prompt Engineering is about discovering magical words that unlock perfect answers.

It isn't.

Most of the time, better prompts come from answering simple questions:

  • What exactly do I want?

  • Who is the audience?

  • What format should the answer have?

  • Is there anything the AI should avoid?

If you can answer those questions clearly, you're already writing good prompts.

As you gain experience, you'll naturally learn more advanced techniques.


Quick Recap

Here's what we learned:

  • A prompt is simply the instruction you give to AI.

  • Better prompts usually produce better responses.

  • Give enough context so the AI understands your goal.

  • Role prompting changes how the AI responds.

  • Few-shot prompting teaches the AI using examples.

  • Output formatting makes responses easier to read.

  • Generation parameters control creativity and response length.

  • Most beginners can leave the default generation settings unchanged.

Clear Prompt
      │
      ▼
AI Understands Better
      │
      ▼
Better Response
Enter fullscreen mode Exit fullscreen mode

Key Takeaways

Prompt Engineering is less about learning secret tricks and more about learning to communicate clearly.

Think of AI as a very knowledgeable assistant. It can help with many tasks, but it doesn't automatically know your goal. The clearer your instructions, the better the result.

As you continue your AI journey, you'll discover that even small improvements in your prompts can make a big difference in the quality of the answers you receive.

Closing Note

This article covered the foundations of Prompt Engineering. In future articles, we'll explore advanced topics such as chain-of-thought prompting, reasoning models, prompt chaining, system prompts, structured outputs, and prompt optimization techniques.

This post was initially published on my blog. Check out the original source using the link below:

Top comments (0)