Prompting Basics & Taxonomy
Learning Objectives
- You understand what prompting is and how prompts influence large language model outputs.
- You know the key components that make up effective prompts.
- You can identify different types of prompts and their purposes.
What is prompting?
Interaction with large language models happens through prompting — writing text that serves as the instruction or starting point for the model’s response. The prompt is the input that guides what the model generates, and even small changes to the prompt can significantly alter the output.
In this part, when referring to a model, we mean a capable large language model that has been fine-tuned for following instructions.
A prompt can take many forms: a question, a statement, an instruction, or simply text to continue. Let’s examine these different approaches.
Questions
A straightforward way to prompt a model is to ask a direct question:
What is the capital of Finland?
The capital of Finland is Helsinki.
Statements
You can also provide a statement. The model will often engage with or correct the statement:
Turku is the capital of Finland.
Actually, Helsinki is the capital of Finland. Turku is one of the country's oldest cities and was historically the capital before Helsinki was designated as the capital in 1812. Turku is known for its rich history, beautiful archipelago, and vibrant cultural scene.
Instructions
Direct instructions tell the model what action to perform:
Please translate the Finnish sentence "Hei maailma!" into English.
The Finnish sentence "Hei maailma!" translates to "Hello world!" in English.
How models generate text
As the models have been trained to predict the next word in a sequence, they generate text by continuing from the prompt. The prompt does not have to be a question or an instruction; it can be any text that sets the context.
Consider this example where we provide the beginning of a poem:
Roses are red, violets are blue, right now I am thinking of ...
a world where dreams come true.
The model recognizes the familiar poem structure and continues in a way that maintains both the structure and rhythm.
The influence of context
The model interprets each word in context with all other words in the prompt. This is the key strength of the attention mechanism in transformers. Small changes to the prompt can shift the context and thus the output.
If we change “violets” to “hamburgers,” the model still recognizes the rhyming structure:
Roses are red, hamburgers are blue, right now I am thinking of ...
Something that rhymes with "blue" and relates to the context you've given. How about "a barbecue"?
But if we deviate further from the classic poem structure, the model no longer generates verse:
Roses are in the garden, hamburgers are on the grill, right now I am thinking of ...
A delightful summer gathering or barbecue party!
Interestingly, a single word can shift the context back. Replacing “hamburgers” with “violets” reactivates the poem structure:
Roses are in the garden, violets are on the grill, right now I am thinking of ...
It seems like you're playing around with the classic poem structure "Roses are red, violets are blue." If you're looking for a continuation, here's a suggestion:
Roses are in the garden, violets are on the grill,
Right now I am thinking of a thrill.
Adventure calls, with excitement to fulfill,
Embarking on a journey, up every hill.
These examples demonstrate how models interpret prompts based on structure and content. By adjusting your prompt, you can guide the model toward specific styles or contexts.
Large language model outputs are typically non-deterministic. The same prompt can yield different responses, especially when prompts are not carefully crafted or when the model uses sampling during generation.
Prompt anatomy: Key components
Effective prompts typically contain several components, though not every prompt needs all of them. The most common components are:
-
The instruction that specifies what you want the model to do. It can be explicit (“Translate this text”) or implicit (providing text that clearly expects continuation).
-
The context that provides background information to help the model understand the situation, domain, or perspective from which it should operate. Context might include the time period, subject area, audience, or relevant constraints.
-
The input data that is the specific content the model should process — the text to summarize, the code to debug, the question to answer, or the information to transform.
-
The output format specifications that tell the model how to structure its response — as a list, a single sentence, JSON format, a table, or any other structure.
Example: Multiple components
Consider this prompt: “Summarize the main research findings of quantum technology during the 21st century in one sentence, focusing on advances in hardware.”
Summarize the main research findings of quantum technology during the 21st century in one sentence, focusing on advances in hardware.
In the 21st century, quantum technology research has achieved significant milestones in hardware, including the development of more stable and scalable qubits, enhanced quantum error correction, and the demonstration of quantum supremacy, leading to the advancement of quantum computers towards practical applications.
This prompt contains:
- Instruction: “Summarize the main research findings”
- Context: “quantum technology during the 21st century” and “focusing on advances in hardware”
- Input data: Implicit — the model draws on its training knowledge
- Output format: “in one sentence”
Example: Data transformation
This prompt demonstrates instruction, input data, and output format:
Please transform the following CSV file into a JSON object. The CSV data starts after ###. Only provide the JSON object as an output.
###
name,year
Philosopher's Stone,1997
Chamber of Secrets,1998
Prisoner of Azkaban,1999
[
{"name": "Philosopher's Stone", "year": "1997"},
{"name": "Chamber of Secrets", "year": "1998"},
{"name": "Prisoner of Azkaban", "year": "1999"}
]
The prompt includes:
- Instruction: “Please transform the following CSV file into a JSON object”
- Input data: The CSV data after the delimiter
- Output format: “Only provide the JSON object as an output”
Prompt taxonomy: Types and purposes
Prompts can be categorized in several ways based on their structure, purpose, and the techniques they employ.
By interaction style
-
Direct prompts ask straightforward questions or give simple instructions without additional context or examples. Example: “What is photosynthesis?”.
-
Conversational prompts engage the model in multi-turn dialogue, building on previous exchanges. Example: A series of follow-up questions that reference earlier responses in the conversation.
-
Instructional prompts provide clear, specific directions about what the model should do and how. Example: “Write a professional email declining a job offer. Use a polite tone and keep it under 150 words.”
By technique
-
Zero-shot prompts ask the model to perform a task without providing examples. Example: “Classify this review as positive or negative: ‘The product broke after two days.’”
-
Few-shot prompts include examples of the desired input-output pattern before asking the model to process new input. Example:
Translate English to French: sea otter => loutre de mer peppermint => menthe poivrée plush giraffe => girafe peluche cheese => -
Chain-of-thought prompts encourage the model to show its reasoning process step-by-step. Example: “Let’s think step by step: If a train leaves at 2 PM traveling at 60 mph, and another leaves at 3 PM traveling at 80 mph, when will the second train catch up?”
By complexity
-
Simple prompts contain a single, straightforward request.
-
Compound prompts combine multiple instructions or constraints. Example: “Summarize this article in three bullet points, using language appropriate for high school students, and highlight any controversial claims.”
-
System-level prompts establish overall behavior or persona that should apply throughout a conversation (system-level prompts are typically used when building LLM-powered applications to constrain the LLM behavior).
Iterative refinement: From simple to complex
Effective prompt engineering often involves starting simple and progressively adding constraints or clarifications. Let’s explore this process with a tourism example.
We begin with a basic question:
What would you suggest seeing in Helsinki?
Helsinki, the capital of Finland, offers a blend of natural beauty, historic architecture, and modern design. Here are some of the top sights and attractions to consider when visiting Helsinki:
Suomenlinna Sea Fortress: A UNESCO World Heritage site, Suomenlinna is a historical maritime fortress and one of Finland's most popular sights. It's a great place to learn about Finnish history or just wander around and enjoy the sea views.
Helsinki Cathedral: Located in Senate Square, this iconic white cathedral is one of the city's most recognizable landmarks.
Market Square (Kauppatori): This bustling market by the sea offers a range of Finnish foods and handicrafts. It's especially lively during the summer.
Uspenski Cathedral: An Eastern Orthodox cathedral with stunning architecture, it offers a glimpse into the Russian influence on Finnish history.
Design District: Helsinki is known for its design culture, and this district is packed with design and boutique stores, galleries, and more.
Kiasma Museum of Contemporary Art: A striking modern building that houses an impressive collection of contemporary artworks.
Seurasaari Open-Air Museum: An island museum that showcases traditional Finnish life with old wooden buildings brought from all over Finland.
Ateneum Art Museum: The Finnish National Gallery's collection of classical art, which includes works by Finland's most renowned artists.
Oodi Helsinki Central Library: A striking modern piece of architecture that's much more than just a library. It's a community space with various amenities and beautiful views of the city.
Temppeliaukio Church (Rock Church): This unique church is excavated directly into solid rock, making it a popular attraction.
Linnanmäki Amusement Park: A historic amusement park, it's fun for all ages and offers a beautiful view of the city from its observation tower.
Esplanadi: A popular urban park in the heart of the city, great for relaxing, people-watching, or enjoying a coffee in one of the adjacent cafés.
Sauna Culture: Experiencing a traditional Finnish sauna is a must when visiting Helsinki. There are several public saunas like Löyly and Allas Sea Pool.
Hietaniemi Beach: If you're visiting in the warmer months, this is a popular sandy beach to enjoy the sun and take a swim.
Moomin Shop: For fans of the beloved Finnish children's book series by Tove Jansson, this shop is a must-visit.
Remember that the best way to experience Helsinki is to wander its streets, enjoy its parks, and engage with the locals. Whether you're into history, design, or nature, Helsinki has something to offer.
The response is comprehensive but quite long. We add an output format constraint:
What would you suggest seeing in Helsinki? Provide only five suggestions.
Certainly! Helsinki is a vibrant city with a mix of historical and contemporary attractions. Here are five must-visit places:
Suomenlinna Fortress: A UNESCO World Heritage site, Suomenlinna is an inhabited sea fortress built on six islands. It's not just a popular tourist attraction, but also a local favorite for picnics and relaxation. The fortress provides a fascinating glimpse into Finnish military and maritime history.
Helsinki Cathedral: An iconic symbol of the city, this majestic white cathedral dominates the Senate Square. It's a great example of neoclassical architecture, and the steps leading up to the cathedral offer a popular gathering place and a fantastic view of the central part of the city.
Market Square (Kauppatori): Located by the sea in the city center, this bustling square is a hub of activity. It offers a variety of seasonal goods, traditional Finnish foods, and souvenirs. Nearby, you can also find the Old Market Hall, which is an indoor marketplace that has been serving customers since 1889.
Design District: Helsinki is renowned for its design and architecture. The Design District comprises several blocks packed with design and antique shops, fashion stores, museums, art galleries, restaurants, and showrooms. Here, you can explore Finnish design, from its classics to contemporary innovations.
Kiasma Museum of Contemporary Art: If you're interested in modern and contemporary art, Kiasma is a must-visit. The museum's architecture itself is a piece of contemporary art, and it houses an impressive collection of Finnish and international contemporary art.
These are just a few highlights of what Helsinki has to offer. The city's unique blend of East and West, its design-centric ethos, and its beautiful natural surroundings make it a memorable destination.
Now we have five suggestions, but suppose we’re planning to walk. We add contextual constraints:
What would you suggest seeing in Helsinki? Provide only five suggestions. Suggest only locations that can be reached by walking.
Certainly! Helsinki is a walkable city with many attractions close to each other. Here are five must-visit sites that are accessible by walking in Helsinki:
Helsinki Cathedral (Tuomiokirkko): Located in Senate Square, this iconic white church with green domes dominates the city skyline. It's not just an architectural masterpiece but also an essential part of Helsinki's history.
Market Square (Kauppatori): Located by the sea, this bustling market offers a mix of Finnish products and food. It's a great place to experience local culture, grab a bite, or just enjoy the harbor views.
Esplanadi Park (Esplanadin puisto): A green oasis in the middle of the city, the Esplanadi is lined with cafes, restaurants, and boutiques. It's an ideal spot to relax, people-watch, or enjoy events that frequently take place there.
Old Market Hall (Vanha Kauppahalli): Located near Market Square, this historic building houses various vendors selling fresh produce, meat, fish, baked goods, and more. The interior has retained its old-world charm, and it's a delightful place to experience Finnish cuisine.
Uspenski Cathedral: This is the largest orthodox church in Western Europe, with its golden cupolas and red-brick facade offering a stark contrast to the Helsinki Cathedral. Overlooking the harbor, it offers a unique blend of Russian and Finnish history and provides great views of the city.
All these attractions are centrally located and can be easily reached by walking. Enjoy your time in Helsinki!
Finally, we want just the names without descriptions. We add another output format specification:
What would you suggest seeing in Helsinki? Provide only five suggestions. Suggest only locations that can be reached by walking. Only list the names of the locations.
Certainly! Here are five walkable attractions in Helsinki:
Helsinki Cathedral
Market Square (Kauppatori)
Uspenski Cathedral
Esplanadi Park
Old Market Hall (Vanha Kauppahalli)
Through iterative refinement, we’ve moved from a lengthy general response to a concise, focused list that meets our specific needs.
Open the AI chat from the lower right corner of the screen. Ask the AI to generate a list of attractions for a city you’re interested in. Start with a well-known city, then try a smaller one. Does the model produce valid outputs? Try refining your prompt with additional constraints.
Best practices for prompting
While prompt engineering remains partly exploratory, several best practices have emerged from research and practical experience. The OpenAI Prompt Engineering Guide highlights six key strategies:
-
Write clear instructions: Be specific about what you want. Ambiguous prompts lead to unpredictable outputs.
-
Provide reference text: When relevant, include reference material or examples that demonstrate what you’re looking for.
-
Split complex tasks into simpler subtasks: Break down complicated requests into a series of simpler prompts. This often produces better results than trying to accomplish everything at once.
-
Give the model time to “think”: For complex reasoning tasks, explicitly ask the model to work through the problem step-by-step rather than jumping to conclusions.
-
Use external tools: For tasks requiring current information, calculations, or data retrieval, consider integrating external tools rather than relying solely on the model’s training data.
-
Test changes systematically: When refining prompts, change one element at a time so you can understand what improves or degrades performance.
Modern language models have been trained on prompting best practices, so you can also ask them for guidance on how to construct effective prompts.
If your work involves regular prompting, consider maintaining a prompt library — a collection of tested prompts that work well for your specific tasks.
A prompt library serves as a reference when constructing new prompts and can be shared with colleagues, allowing your team to benefit from collective experience. Include notes about when each prompt works well and any limitations you’ve discovered.