No history yet

Introduction to Prompt Engineering

What is Prompt Engineering?

Think of a large language model (LLM) like a incredibly knowledgeable, but very literal, assistant. It knows almost everything, but it doesn't know what you want until you tell it. Prompt engineering is the art and science of telling it exactly what you want, in a way it can understand.

Prompt engineering is the practice of crafting inputs—called prompts—to get the best possible results from large language models.

A good prompt is the difference between a vague, useless answer and a precise, helpful one. It's not about complex coding. It's about clear communication. By learning how to craft your requests, you can guide the AI to generate better summaries, create more relevant content, and provide more accurate analysis.

Basic Prompting Techniques

The simplest way to interact with an LLM is through zero-shot prompting. This is what you do when you ask a question without giving any prior examples. You're relying on the model's vast pre-existing knowledge to figure out what you mean and provide a good answer.

For example, asking an LLM to classify the sentiment of a sentence is a zero-shot prompt. You haven't shown it what a positive or negative sentence looks like; you're assuming it already knows.

Classify the sentiment of this review:

"The movie was a fantastic journey from start to finish!"

Sentiment:

But what if the task is more specific or nuanced? That's where few-shot prompting comes in. With this technique, you give the model a few examples—or "shots"—of what you're looking for. This helps it understand the pattern you want it to follow.

Giving the model a few examples sets the context and shows it the desired format for the output. It's like showing a new employee a few completed reports so they understand how to structure their own.

Classify the sentiment of these reviews as 'Positive' or 'Negative'.

Review: "I couldn't get through the first 20 minutes."
Sentiment: Negative

Review: "An absolute masterpiece of modern cinema."
Sentiment: Positive

Review: "It was okay, but not what I expected."
Sentiment: Negative

Review: "The movie was a fantastic journey from start to finish!"
Sentiment:

Understanding the Model

LLMs aren't thinking in the human sense. They are incredibly sophisticated pattern-matching systems. At their core, they work by predicting the most probable next word in a sequence, based on the patterns they learned from trillions of words of text data. The prompt you provide is the starting point for this prediction process.

Lesson image

This is why clarity is so important. A vague prompt gives the model too many possible patterns to follow, leading to generic or irrelevant results. A specific prompt narrows the possibilities and guides the model toward the pattern that produces your desired output. You're essentially setting up a strong starting pattern for the model to complete.

Crafting Better Prompts

The best prompts are clear, concise, and direct. They leave little room for misinterpretation. Avoid ambiguity and use simple language. Think about what a perfect answer would look like, and then work backward to write a prompt that would generate it.

Bad PromptGood Prompt
Write about sales.Write a three-paragraph email to the sales team summarizing Q2 performance and outlining the top 3 goals for Q3.
Explain AI.Explain the concept of machine learning to a 10th-grade student, using an analogy related to learning to play a video game.
Give me some blog ideas.Act as a content marketing expert. Generate 5 blog post ideas about the benefits of remote work for small businesses. For each idea, provide a catchy title and a short, two-sentence description.

A highly effective prompt often includes several key elements:

  • Role: Tell the model who it should be (e.g., "Act as an expert copywriter...").
  • Task: Clearly state what you want it to do (e.g., "...write three headlines...").
  • Context: Provide necessary background information (e.g., "...for a new brand of eco-friendly coffee.").
  • Format: Specify how you want the output structured (e.g., "Provide the answer as a bulleted list.").
  • Constraints: Set boundaries or rules (e.g., "Keep the tone professional and the length under 100 words.").

Not every prompt needs all these elements, but including them when needed will dramatically improve your results.

Ready to check your understanding? Let's see what you've learned.

Quiz Questions 1/5

What is the primary goal of prompt engineering?

Quiz Questions 2/5

If you provide an LLM with several examples of a task before asking it to perform that same task on new data, what is this technique called?

Mastering these basics is the first step. By communicating clearly and providing context, you can turn a powerful tool into a truly useful partner.