No history yet

Introduction to Prompt Engineering

What Is Prompt Engineering?

Working with a large language model (LLM) is like having a conversation. You give it an instruction, and it gives you a response. That instruction is called a prompt. The art and science of crafting that instruction to get the best possible result is called prompt engineering.

It's the same principle in prompt engineering, as detailed coffee orders lead to better coffee, specific good prompts can produce more relevant and refined AI responses.

If you walk into a coffee shop and just say "coffee," you'll get a plain black coffee. But if you ask for a "large iced oat milk latte with two shots of espresso and one pump of vanilla syrup," you get exactly what you want. The LLM is the barista; your prompt is the order. The more specific and clear your instructions, the better the outcome.

Lesson image

Prompt engineering matters because LLMs are incredibly powerful, but they aren't mind readers. They rely entirely on the input you provide to understand your goal. A well-designed prompt guides the model, reduces the chance of getting a generic or incorrect answer, and helps you unlock the AI's full potential.

The Anatomy of a Good Prompt

Effective prompts usually contain a few key ingredients. While you don't always need every single one, thinking about them will help you structure your requests more clearly.

Instruction: This is the core task you want the AI to perform. It's a direct command, like "Write," "Summarize," "Translate," or "Explain."

For example: Explain the concept of photosynthesis.

Context: This is the background information the model needs to complete the task well. It helps narrow the focus and provides necessary details. Who is the audience? What style should it use?

Adding context to our previous example: Explain the concept of photosynthesis to a fifth-grade student.

Format: This specifies how you want the output to be structured. Do you want a paragraph, a list, a table, or code? Being explicit about the format saves you time editing later.

Finishing our example: Explain the concept of photosynthesis to a fifth-grade student. Use a simple analogy and present the key steps as a numbered list.

Basic Principles in Action

Let's see how these elements make a practical difference. Clarity and specificity are your best friends.

Weak PromptStrong Prompt
Tell me about pasta.Create a table comparing three popular types of pasta: spaghetti, penne, and fettuccine. Include columns for their shape, common sauce pairings, and a fun fact about each.

The weak prompt is vague and would likely produce a long, unfocused wall of text. The strong prompt is specific, provides context (comparing three types), and defines the exact format (a table with specific columns). The result from the second prompt will be far more useful and require less work from you.

Another powerful technique is to give the model an example of what you want. This is sometimes called "few-shot prompting."

Imagine you want the model to classify customer feedback as positive, negative, or neutral. Instead of just asking it to classify a new comment, you can show it what you mean first.

Classify the sentiment of the following customer reviews as Positive, Negative, or Neutral.

Review: "The battery life on this phone is amazing!"
Sentiment: Positive

Review: "The screen scratches too easily."
Sentiment: Negative

Review: "The package arrived on time."
Sentiment: Neutral

Review: "I'm not sure if I like the new update."
Sentiment:

By providing examples, you've trained the model on the fly for your specific task. It now has a crystal-clear understanding of the desired output format and logic, making its response on the final review much more reliable.

Time to check your understanding.

Quiz Questions 1/4

In the context of working with a large language model (LLM), what is a 'prompt'?

Quiz Questions 2/4

Which of the following prompts is most likely to produce a detailed and useful comparison of electric cars for a potential buyer?

Mastering these basics is the first step. Prompting is an iterative process—you'll often refine your prompts based on the AI's responses to get closer to the perfect result.