In the last Part we covered some basic definitions and why exactly prompt engineering is important.
We’re now going to get more into the nitty gritty and tackle some topics like “few-shot prompting” and other buzzwords you may have heard flying around.
Don’t worry - none of this is particularly complex! And I’ll use simple language and examples so that it’s (hopefully) nice and simple.
Let’s start basic.
Prompts at their core are just text strings containing instructions for the AI.
However, how you structure that text matters. Here are some prompt syntax best practices:
Adhering to basic syntactic conventions will make your prompts clearer and easier for the AI to parse.
Effective prompts generally contain some combination of the following key components:
Context not assuming knowledge
Don’t assume the AI knows what you want. Instead treat them like you would an intern - someone who is intelligent but doesn’t know how things work yet. You have to provide context around your prompt to give all the information required to complete the task.
Instructions not Questions
Don’t use questions with AI in the same way you might on Google. Asking questions leads to more wishy-washy answers. Instead instructions work far better.
Examples
Don’t be annoyed when the AI provides an output that doesn’t match what you are expecting. You need to show the AI what a good output looks like so that it can best match your expectations.
Constraints
Telling an AI what to exclude is just as, if not more, important as telling it what you want. AIs can generate pretty much anything so being precise about what you don’t want in an output helps them to focus.
There’s a lot to remember here so I’ve coined a nice memory aid.
I use the RISEN method:
For example:
Act as a master chef. (Role)
Give me a 5 step recipe for baked chicken breast. (Instructions)
1. tell me the ingredients needed
2. the steps to prepare
3. cooking instructions
(steps)
Give me everything in a checklist (End goal)
Keep these constraints in mind:
-Use only common ingredients
-Include approximate cooking times and temperatures
-Keep the recipe under 500 words
-Do not include any complicated techniques
-Focus just on the core recipe steps
(Narrowing)
The RISEN framework provides a structured way to build prompts that guide the AI to high-quality responses tailored to your needs.
Apply it to your tasks to immediately see improvements across the board.
Yes, your prompts will take longer to write but the results will propel you immediately from an amateur to an intermediate user.
Now let's explore some of the most common and effective prompting techniques used in prompt engineering. The RISEN formula above is a good base line.
But sometimes we need to go further - this section will talk about some of the common techniques.
These are situational. Some are good at some tasks, others are not. I suggest you just play around with them, get used to the concept and then when tackling real world prompting problems you’ll have these to fall back on.
Instruction prompting involves giving the AI clear step-by-step directions to accomplish a task. This technique enables generative models to complete complex objectives that go far beyond their default capabilities.
Key Tips for Instruction Prompting
Instruction Prompting Examples
Data Cleaning
Instructions can automate tedious data processing tasks. For example:
"Parse the following name field into separate first name and last name columns. Handle names with titles like Mr. or Dr. as well as suffixes like Jr. or III."
Content Generation
Instructions can guide quality content creation. For example:
"Write a 300 word blog post about prompt engineering. Focus on clearly explaining key concepts and provide actionable examples. Use subheadings to improve scannability."
Content Moderation
Instructions enable automatic content filtering. For example:
"Review the following text. Remove any profanity, hate speech or offensive language. Replace it with [REMOVED]."
Feedback and Analysis
Instructions can produce detailed evaluations. For example:
"Analyze this essay on a scale of 1-10 for grammatical correctness, logical coherence, strength of arguments, and overall quality. For each criterion, explain your rating."
The key with instruction prompting is starting with simple, straightforward directions and iteratively building on them to tackle more complex tasks.
Role prompting involves assigning the AI a specific persona, character, or identity to shape its responses. This technique allows prompt engineers to control the style, tone, and depth of generated content.
When to Use Role Prompting
Role prompting is useful when you want the AI to:
How to Role Prompt Effectively
Follow these tips for effective role prompting:
Examples
Writing Style
"You are a travel writer for a lifestyle magazine. Describe the nightlife in Paris in a lively and engaging tone."
Domain Expertise
"You are an experienced java programmer. Explain polymorphism in Java for a coding tutorial."
Audience Tailoring
"You are a kindergarten teacher. Briefly explain photosynthesis in simple terms a 5 year old could understand."
Fictional Roleplay
"You are detective Sherlock Holmes. Deduce how the crime was committed based on these clues."
Pitfalls to Avoid
Few-shot prompting sounds fancy.
All it involves is providing the AI with 2 or more example inputs and outputs to demonstrate the desired format. This technique is useful for structuring outputs in a specific way.
How Few-Shot Prompting Works
When to Use Few-Shot Prompting
Use few-shot prompting when:
This is much easier to understand via examples.
Structured Data Extraction
Article: John Smith is a doctor in New York.
Output: John Smith [DOCTOR]
Article: Jane Doe is a lawyer in Washington.
Output: Jane Doe [LAWYER]
Article: Chris Lee is an architect in Chicago.
Output:
Will output “[Architect]”
Translation
English: The book is on the table.
Spanish: El libro está sobre la mesa.
English: Where is the bathroom?
Spanish: ¿Dónde está el baño?
English: I would like water.
Spanish:
Will output “Me gustaría agua.”
As you can see from the examples the AI will look for the pattern and seek to “fill in the gaps”.
You may have also heard of these alternatives so I’m dropping them for clarity.
In summary, few-shot prompting is a simple yet powerful technique for structuring AI outputs in a customized format.
OK phew we’ve covered a lot! Good job.
In the next part we’ll start looking at how to actually apply all of this new knowledge in real world projects!