Introduction

Welcome to this lesson on enhancing prompt engineering with examples. In previous lessons, we discussed the importance of structured prompts and defining constraints. Today, we'll explore how examples can significantly improve the quality and format of responses from Large Language Models (LLMs). By the end of this lesson, you'll understand how to effectively use examples to guide LLMs in producing structured and relevant answers.

Basic Prompt Performance

Let's start by examining a basic prompt without any examples or constraints. This will help us understand the limitations of such prompts.

Context:

I want to print 10 cards with choose-one question about domestic animals for my students

Ask:

Come up with 10 questions with three answer options, where one answer is correct

Without any examples or constraints, the LLM might generate questions that are not well-structured or relevant. The lack of guidance can lead to varied formats and potentially incorrect or unclear options.

Here is an example of LLM's answer:

Here are 10 choose-one questions about domestic animals, each with three answer options:

1. **Question:** Which animal is commonly known as "man's best friend"?
   - A) Cat
   - B) Dog
   - C) Rabbit
   - **Correct Answer:** B) Dog

...
Enhancing Prompts with Examples

Now, let's see how including an example can improve the LLM's response. An example provides a clear template for the LLM to follow, ensuring consistency and relevance.

Context:

I want to print 10 cards with choose-one question about domestic animals for my students

Ask:

Come up with 10 questions with three answer options, where one answer is correct

Example:

- Question: What is the primary purpose of a domestic cat's whiskers?
   1. To help them see in the dark
   2. To detect changes in their surroundings [correct]
   3. To keep them warm

By including this example, we guide the LLM to format its responses similarly.

Refining Responses with Constraints

Next, let's introduce constraints to further refine the LLM's output. Constraints help ensure that the LLM adheres to specific requirements, improving the precision of its responses.

Constraints:
- Do not include the example question in your answer, come up with new ones
- Don't include any introduction or conclusion

These constraints instruct the LLM to avoid repeating the example question and to focus solely on generating new content without unnecessary introductions or conclusions.

Summary and Preparation for Practice

In this lesson, we explored how examples and constraints can enhance the quality of LLM responses. By providing a clear example, we guide the LLM to follow a specific format, while constraints ensure precision and relevance. As you move on to the practice exercises, experiment with different examples and constraints to see how they impact the LLM's output. This hands-on practice will solidify your understanding and help you become proficient in prompt engineering.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal