Back to blog

Feb 17 2024

Introduction to Prompt Engineering

Hello again!

So I'm sure everyone and their mom has heard of artificial intelligence being thrown around these days, but not everyone has a firm understanding of how these tools might be able to benefit you. That is the subject of this post. Today we will be diving into Prompt Engineering! Before we get into our post, let's define some key terminology that we will be using to help illustrate the topic:

Ok great, now that we have that squared away, let's get started.

Have you tried interacting with an LLM before? There are different LLMs out there for different use cases with a wide range of capabilities. Some LLMs can generate creative text formats like poems or code, while others may focus on something more specific like writing a script for a movie. Depending on what you're hoping to achieve, there is likely a specific LLM to fit your needs that is just a Google search away. Here are a few free LLM offerings to get you started with prompts:

It can be overwhelming to choose which product to use when learning to use LLMs, so I would suggest just sticking with Google Gemini or ChatGPT to get your feet wet as these are general purpose LLMs that fit most if not all use cases. For the purposes of this post, we will be using Google Gemini to help illustrate prompt engineering. To follow along, first navigate to the Google Gemini app here. You will likely have to create an account or login if you already have a Google account. Once in, you should see something like this on your screen:

Gemini Home Screen

Before we get going, let's talk more about prompts. What are they? Well, they are the inputs that we provide to LLMs. They can contain questions, instructions and really anything you can think of as being useful when trying to instruct an LLM to achieve a task. What are some different input types that you can think of when addressing one of your friends that might be applicable for addressing an LLM? Here's a list of some common LLM inputs:

Hopefully that gets your brain thinking about the possibilities of prompts that one might be able to use. But let's get back to using an LLM now so we can apply what we've learned.

Navigating back to Gemini, you should see a greeting at the top of the screen and more importantly, a text input at the bottom of the screen with a placeholder of "Enter a prompt here". This input field is how we will be interacting with Google Gemini. Let's try it out. Use some of the prompts we defined above for the different types. How were the results? Do you think additional context would help LLMs? Take this example prompt:

Pets:
Dogs: 2
Cats: 4
Hamsters: 1
Cows: 0
How many cats are there?
Gemini Response

Gemini's Response

Gemini responds with four cats. Wow! The additional context helps Gemini scope the problem with boundaries and helps it generate the response we are looking for. Be sure keep these types of prompts in your tool belt when using LLMs, but let's not stop there. Providing examples to scope a problem is also a helpful method:

Options:
* American
* International
Text: Ford
Answer: American
Text: Toyota
Answer: International
Text: BMW
Answer: International
Text: Lincoln
Answer: American
Text: Honda
Answer:
Gemini Response

Gemini's Response

Gemini responds with "International", nice! Examples are an effective strategy to give the LLM an example of an ideal response and scopes the task down as well. Now let's focus on a particular example to try and explore more. Input the following prompt:

What are some things to do while visiting Los Angeles?

What did Gemini respond with? When I prompted Gemini with that question, I received some recommendations about exploring the Hollywood Walk of Fame, spending a day at the beach and going shopping. How does that compare with your response? If you were visiting Los Angeles would the itinerary that Gemini produced meet your needs? I'm guessing probably not. This is where clear communication, prompt structure and specifics can really start to help us. It also helps to structure our prompt to our particular use case. But what if we wanted Gemini to be our own personal travel agent? We can instruct Gemini to assume that role by giving Gemini context of what we are looking for, similar to how we might address a travel agent:

You are a travel agent working for a top tier agency. You need to understand the customer's goals for travel and then design a prompt. The prompt should include all the relevant information, context and data that was provided to you. You will continue asking questions until you are confident that you can provide the customer the best itinerary possible for their vacation. Start by asking me where I would like to go and then continue with follow-up questions to design the best prompting experience for me.
Gemini Response

Gemini's Response

Wow! That's amazing! We are now having a dialogue with Gemini to better serve our needs as a user. You can continue to have the conversation as you see fit or exit now if you would like. Hopefully you can see the importance of specificity and specifically the part that "role" based prompting plays in working with LLMs. Context and creativity are key to achieve desirable results when working with LLMs. In a later post, I will expand on other techniques folks use to get the most out of LLMs! I highly recommend exploring LLMs and using them as tools to supercharge your life! They are extremely useful when used in the right way!

Thanks for reading and cheers!