Recommended resources
The freely available resources this lesson will direct you to.
Introduction
In our last lesson, we developed a systematic approach for debugging prompts, treating a failing prompt like a buggy piece of code that needs diagnosis and refinement. This skill is crucial for iteration, but the ultimate goal is to architect effective prompts from the very beginning.
This lesson shifts our focus from reactive debugging to proactive design. We will learn how to select the most appropriate prompting strategy for a given task, ensuring you choose the right tool for the job from the start. Your background in software engineering, which involves selecting appropriate algorithms and data structures based on problem requirements, provides a strong parallel to the thinking process we'll cultivate here.
Our learning outcome is to select appropriate prompting strategies for diverse tasks including summarization, extraction, classification, and generation. We will explore a spectrum of techniques, from simple zero-shot instructions to more complex reasoning patterns, and create a mental framework for matching them to the specific demands of common developer-adjacent tasks.
The Building Blocks of a Strategic Prompt
Before matching strategies to tasks, it's essential to have a consistent framework for constructing any prompt. A well-structured prompt is easier to reason about, debug, and adapt. A highly effective and practical model consists of six components.
Master the Perfect ChatGPT Prompt Formula (in just 8 minutes)!
This video from Jeff Su provides an excellent, concise formula for building high-quality prompts. It introduces six key building blocks that we will use as a foundation for our task-specific strategies.
Please watch the entire video (The Prompt Formula). As you watch, pay close attention to the six components and their hierarchy of importance: Task: The specific action you want the LLM to perform. Context: Background information the LLM needs to perform the task. Exemplars: Examples that demonstrate the desired output format or style. Persona: The role you want the LLM to adopt. Format: The desired structure of the output (e.g., table, JSON, markdown). Tone: The stylistic voice of the response (e.g., formal, witty).
Think of this Task-Context-Exemplars-Persona-Format-Tone (TCE-PFT) formula as the universal API for interacting with an LLM. For any given problem, our job is to decide which of these components are necessary and how to populate them. The specific way we populate them—for instance, whether we use zero, one, or multiple exemplars—is what defines our prompting strategy.
Your Toolbox: A Spectrum of Prompting Techniques
With our foundational prompt structure in mind, let's survey the toolbox of specific techniques at our disposal. The infographic below provides a great overview of the most common prompting strategies, ranging from simple to complex.
Our goal is not to memorize every technique, but to understand the trade-offs. The guiding principle is to use the simplest technique that reliably accomplishes the task. You wouldn't use a distributed microservices architecture for a simple "Hello, World!" application; similarly, you don't need a complex ReAct agent for a straightforward summarization task.
Now, let's see how to apply these techniques to the four key task categories.
Matching Prompting Strategies to Tasks
The "art" of prompt engineering lies in recognizing the nature of a task and selecting the corresponding strategy. Below, we'll analyze the requirements for classification, extraction, summarization, and generation.
For a deeper dive into the fundamental techniques we'll discuss, the following guide is an excellent resource. We'll refer to specific sections as we go.
Prompt Engineering Techniques for LLMs
This guide provides detailed explanations, use cases, benefits, and limitations for 11 different prompting techniques.
For now, familiarize yourself with the structure of the article. You don't need to read it all at once; we will be referencing specific sections for each task type. Just know that it's available as a detailed reference.
1. Classification Tasks
In a software context, classification involves assigning an item to a predefined category. This could be categorizing a bug report by severity (Critical, High, Medium), determining user intent from a query ("search", "purchase", "support"), or performing sentiment analysis on user feedback.
-
When to use Zero-Shot Prompting: If your categories are simple and universally understood (e.g.,
Positive,Negative,Neutral), a zero-shot prompt is usually sufficient. The model's pre-training already includes a strong understanding of these concepts.- Strategy: Clearly define the
Taskand provide the text to classify. Crucially, constrain the output by listing the allowedFormat(the categories). - Example:
"Classify the following text as either 'Bug Report', 'Feature Request', or 'Question'. Text: 'The login button is broken on Safari.' Classification:" - Reference: Review Section 1: Zero-Shot Prompting in the "Comprehensive Guide" resource.
- Strategy: Clearly define the
-
When to use Few-Shot Prompting: When you have custom, nuanced, or ambiguous categories, the model needs
Exemplarsto understand the boundaries. For example, classifying developer questions intoBuild System,API Usage, orDocumentation Errorrequires context that few-shot examples can provide.- Strategy: Provide 2-5 high-quality examples (
Exemplars) demonstrating the input-to-category mapping before presenting the new item to classify. - Reference: Review Section 2: Few-Shot Prompting in the "Comprehensive Guide" resource.
- Strategy: Provide 2-5 high-quality examples (
2. Extraction Tasks
Extraction is about pulling structured data from unstructured text. This is a cornerstone of many developer workflows: parsing configuration files, extracting key-value pairs from log messages, or pulling contact information from an email.
-
Strategy: Zero-Shot with Strict Formatting. The most critical component for extraction is the
Formatspecifier. Modern LLMs are very good at generating structured data like JSON or XML if you ask for it explicitly.- Prompt:
"Extract the user's name, email, and company from the following text. Provide the output as a JSON object with the keys 'name', 'email', and 'company'. Text: '...'. JSON:" - Your experience with data structures and APIs makes the value of this immediately apparent. Requesting a well-defined schema turns the LLM into a powerful, on-the-fly parser. The
Formatsection of Jeff Su's video (LINK) showed a great example of requesting a table.
- Prompt:
-
When to use Few-Shot: If the extraction logic is complex and hard to describe with instructions alone, providing an
Exemplarcan clarify the pattern. For instance, extracting non-standard date formats or complex relational data.
3. Summarization Tasks
Summarization tasks condense information. The key is not just to shorten the text but to do so according to specific goals.
- Strategy: Zero-Shot with Strong Constraints and Persona. Summarization is less about a specific technique and more about expertly using the
Task,Persona, andFormatcomponents.- Constraints on Length/Focus: Be explicit.
"Summarize the following technical document in three bullet points, focusing on the impact to the API." - Persona for Style/Audience: The
Personadictates what information is considered important."You are a senior engineering manager. Summarize this incident report for an executive audience, focusing on business impact and remediation steps.""You are a junior developer. Summarize this pull request for your own notes, focusing on the new functions you need to learn."
- Constraints on Length/Focus: Be explicit.
4. Generation Tasks
Generation is the broadest category and includes writing code, documentation, emails, or test plans. Here, you'll often combine multiple strategies.
- For Styled/Formatted Content: Use
Persona,Tone, andExemplarsto guide the style. For example, to generate a design document, you could provide anExemplarof a previous document's structure. - For Complex, Multi-Step Logic (e.g., writing a function): When the task requires reasoning, it's time to bring in a more advanced technique.
- Chain-of-Thought (CoT): If a task involves multiple logical steps (e.g., designing an algorithm, planning a database migration), instructing the model to "think step-by-step" improves reasoning quality. This exposes the model's logic, which you can then refine, as we discussed in the last lesson.
- Reference: Review Section 3: Chain-of-Thought Prompting in the "Comprehensive Guide" resource.
An Empirical Approach to Strategy Selection
So far, our recommendations have been based on heuristics. However, selecting a prompting strategy can also be informed by empirical data. The choice of strategy can depend not just on the task, but on the specific model you are using.
The following article provides a fascinating look at how different models (GPT, Claude, Llama families) respond to various prompting strategies for classification and summarization tasks. For someone with your technical background, these data-driven insights are invaluable.
Optimizing Prompts Across LLMs
This research-based article moves beyond anecdotal advice and provides concrete data on what works best for different models and tasks.
Please read two key sections of this article: Start with the section "Key Findings Overview". Pay close attention to the specific results for Model Family Performance Patterns (e.g., Claude models excelling with XML), Input Context Placement, and the impact of Chain-of-Thought. Next, read the section "High-Level Recommendations". This section synthesizes the findings into actionable advice, covering General Best Practices, Model-Specific Guidelines, and Task-Specific Strategies. This directly addresses our learning outcome.
The key insight from this research is that optimal prompting is not a one-size-fits-all discipline. Factors like whether to use few-shot examples, where to place context, and what format to use can have a measurable impact on performance, and the best choice may differ between models like GPT-4 and Claude Opus.
Conclusion
In this lesson, we've built a framework for moving from simply writing prompts to strategically engineering them. By understanding the demands of a task, you can now select the most effective and efficient prompting technique from your toolbox.
Here are your key takeaways:
- Start with a Framework: Every prompt benefits from a clear structure. Use the
Task-Context-Exemplars-Persona-Format-Tonemodel as your mental checklist. - Match Strategy to Task Complexity:
- Classification: Use zero-shot for simple cases and few-shot for custom categories. Pay attention to model-specific formatting (e.g., XML for Claude).
- Extraction: Prioritize clear instructions and a strict
Formatspecification (like JSON). - Summarization & Generation: Use
Persona,Tone, and strongConstraintsto control the output.
- Escalate When Reasoning is Required: For tasks involving multiple logical steps, escalate from simple zero-shot to Chain-of-Thought to improve the robustness of the model's reasoning.
- Be Empirical: The best strategy is often model-dependent. Insights from data-driven analysis, like the ones in the recommended article, provide a significant advantage over pure trial-and-error.
This lesson concludes our module on Advanced Prompting Techniques. You now have a comprehensive understanding of how to craft, debug, and select prompts for a wide variety of tasks.
In our next lesson, we will begin the "AI-Assisted Development" module. You'll apply the prompting skills you've honed to the daily workflows of a software developer, starting with leveraging advanced features of AI coding assistants to generate, debug, and test code.