Chapter 8 Exercises: Prompt Engineering Fundamentals
These exercises are organized into five tiers based on Bloom's taxonomy, progressing from basic recall to creative challenges.
Tier 1: Recall (Exercises 1-7)
These exercises test your ability to remember key concepts from the chapter.
Exercise 1: Name the Five Pillars
List the five pillars of an effective code prompt and write a one-sentence definition for each.
Exercise 2: Anti-Pattern Identification
Name at least four prompt anti-patterns discussed in this chapter and briefly explain why each one is problematic.
Exercise 3: Vocabulary Match
Match each term on the left with its correct definition on the right:
| Term | Definition |
|---|---|
| A. First-attempt success rate | 1. Background information the AI needs to understand your project |
| B. Negative constraint | 2. A reusable prompt structure with placeholders |
| C. Context | 3. A specification of what the code should NOT do |
| D. Prompt template | 4. The percentage of prompts producing usable code without follow-up |
| E. Specificity | 5. The calibrated level of detail in a prompt |
Exercise 4: Quality Spectrum Levels
Describe each of the five levels of the prompt quality spectrum (Level 1 through Level 5) in your own words. Give an example prompt fragment for each level.
Exercise 5: Constraint Categories
List the four categories of constraints discussed in Section 8.5 and provide one example of each category that was NOT used in the chapter.
Exercise 6: Clarity Strategies
List at least three strategies for achieving clarity in prompts, as discussed in Section 8.2.
Exercise 7: Template Categories
Name the five prompt template categories provided in Section 8.9 and describe what type of task each template is designed for.
Tier 2: Apply (Exercises 8-14)
These exercises ask you to apply the concepts to practical situations.
Exercise 8: Pillar Diagnosis
For each of the following prompts, identify which pillar(s) are missing or weak and explain why:
a) "Write a sort function."
b) "Using our Django app with the User model I showed you earlier, write something to handle authentication."
c) "Create a Python function called parse_log_entry that takes a string and returns a dictionary. Use regex."
d) "Build me the entire backend for a social media platform."
Exercise 9: Prompt Upgrade — Clarity
Rewrite the following vague prompt to make it clear and unambiguous:
Fix the issue with the data processing.
Assume you are working on a Python data pipeline that reads JSON files, transforms the data, and loads it into a PostgreSQL database. The specific issue is that date strings in the format "MM/DD/YYYY" are not being converted to Python datetime objects.
Exercise 10: Prompt Upgrade — Specificity
The following prompt has the right idea but lacks specificity. Rewrite it with appropriate detail:
Write a function that validates passwords.
Include specific validation rules, parameter types, return type, and behavior for invalid inputs.
Exercise 11: Prompt Upgrade — Context
The following prompt is missing crucial context. Rewrite it with the context you would need to provide to get a useful response:
Add a search feature.
Assume you are building a recipe-sharing web application using Flask, SQLAlchemy, and Jinja2 templates. The database has Recipe, Ingredient, and Category models.
Exercise 12: Prompt Upgrade — Constraints
Add appropriate constraints to the following prompt:
Write a Python function to upload files to S3.
Include at least two constraints from each category: functional, technical, style, and security.
Exercise 13: Prompt Upgrade — Output Format
Rewrite the following prompt to include explicit output formatting instructions:
Review this code and tell me what's wrong.
Specify exactly how you want the review results structured, including severity levels, locations, descriptions, and fixes.
Exercise 14: Full Five-Pillar Prompt
Write a complete prompt using all five pillars for the following task: You need a Python function that connects to a REST API, fetches paginated data, and stores it in a local SQLite database.
Tier 3: Analyze (Exercises 15-21)
These exercises ask you to break down, compare, and evaluate prompts.
Exercise 15: Anti-Pattern Analysis
Read the following prompt and identify ALL anti-patterns present. Explain each one and how it degrades the prompt's effectiveness:
So basically I need you to write me some code that handles our data
and it needs to be fast but also readable and it should use best practices
and handle errors but don't make it too complex just keep it simple but
also make sure it covers all the edge cases and use the right design
patterns and make it production-ready but also easy to understand for
junior developers and also add tests and documentation.
Exercise 16: Prompt Comparison
Below are two prompts for the same task. Analyze each one using the five-pillar framework, score each pillar (1-5), and explain which prompt would produce better results and why:
Prompt A:
Write a caching decorator in Python.
Prompt B:
Write a Python decorator called `cache_result` that caches function return
values based on their arguments.
Requirements:
- Use a dictionary for the cache storage
- Support positional and keyword arguments as cache keys
- Include a `max_size` parameter (default 128) — evict the oldest entry when full
- Include a `ttl` parameter in seconds (default None, meaning no expiration)
- Add a `.cache_info()` method to the decorated function that returns
a namedtuple with hits, misses, and current size
- Thread-safe using threading.Lock
Include type hints, a docstring, and an example of usage.
Exercise 17: Specificity Calibration
For each of the following tasks, determine whether the prompt is too vague, appropriately specific, or overly detailed. Justify your assessment:
a) Task: Reverse a string.
Prompt: "Write a Python function that takes a string parameter named 'input_text' of type str and returns a new string of type str that contains the characters of the input string in reverse order, where the first character becomes the last character and the last character becomes the first character."
b) Task: Build a REST API endpoint for user registration.
Prompt: "Make a registration endpoint."
c) Task: Sort a list of numbers.
Prompt: "Write a Python function that sorts a list of integers in ascending order using the built-in sorted() function. Return the sorted list. Handle empty lists by returning an empty list."
Exercise 18: Context Sufficiency Analysis
For the following prompt, list all the questions an AI assistant might need answered to produce correct code. Then rewrite the prompt to include answers to those questions:
Write the database migration for the new feature.
Exercise 19: Constraint Conflict Detection
Read the following prompt and identify all conflicting or contradictory constraints. Propose a resolution for each conflict:
Write a Python data processing function that:
- Processes files of any size, up to 100GB
- Loads all data into memory for fastest processing
- Uses only the standard library
- Generates charts and visualizations of the results
- Is a single pure function with no side effects
- Writes results to a file and sends an email notification
- Has no external dependencies
- Uses pandas for data manipulation
Exercise 20: Template Fitness
For each of the following tasks, identify which prompt template from Section 8.9 is most appropriate and explain why:
a) Your login function returns a 500 error when the email contains special characters. b) You need a new function that calculates shipping costs based on weight and destination. c) Your colleague's pull request has a function that you suspect has performance issues. d) You want to ensure your payment processing function handles all edge cases. e) The codebase has a 200-line function that needs to be broken into smaller pieces.
Exercise 21: Prompt Evolution
Trace the evolution of a prompt through the quality spectrum. Start with a Level 1 prompt for "create a to-do list API" and write improved versions at each level (2 through 4), adding pillars at each step. Explain what you added at each level and why it matters.
Tier 4: Create (Exercises 22-28)
These exercises ask you to create original prompts and templates.
Exercise 22: Custom Template — Database Query
Create a reusable prompt template for generating database queries. The template should include placeholders for: the database system, tables involved, desired output, filtering criteria, sorting, and performance considerations.
Exercise 23: Custom Template — API Integration
Create a reusable prompt template for integrating with external APIs. Include placeholders for: the API name and documentation, authentication method, endpoints needed, error handling strategy, rate limiting, and data transformation.
Exercise 24: Domain-Specific Prompts
Write three prompts tailored to a specific domain of your choice (e.g., financial software, healthcare, gaming, IoT). Each prompt should demonstrate how domain context changes the way you write prompts compared to generic coding tasks.
Exercise 25: Prompt for Prompt Generation
Write a meta-prompt: a prompt that asks the AI to help you write better prompts for a specific type of task. The meta-prompt should describe your common coding tasks, your technology stack, and your quality standards, and ask the AI to generate reusable templates tailored to your workflow.
Exercise 26: Prompt Evaluation Rubric
Design a detailed rubric for evaluating prompt quality that extends beyond the simple 1-5 scoring table in Section 8.10. Your rubric should include at least three sub-criteria for each pillar, with descriptions of what constitutes poor, adequate, good, and excellent for each sub-criterion.
Exercise 27: Anti-Pattern Catalog
Create three NEW anti-patterns not discussed in the chapter. For each one: - Give it a memorable name - Show an example of the anti-pattern - Explain why it is problematic - Show the corrected version
Exercise 28: Prompt Refactoring Exercise Set
Create a set of five "before" prompts (each with different weaknesses) that could be used as a training exercise for your team. Include a scoring rubric and "model answers" showing the improved versions.
Tier 5: Challenge (Exercises 29-35)
These exercises push you to tackle complex, open-ended problems.
Exercise 29: The Prompt Analyzer
Using the prompt analyzer from code/example-01-prompt-analyzer.py as inspiration, design (on paper or in pseudocode) an enhanced prompt analyzer that:
- Scores prompts on each of the five pillars
- Identifies specific anti-patterns
- Suggests improvements
- Provides example rewrites for weak areas
- Learns from user feedback on which suggestions were helpful
Describe the algorithms and heuristics you would use for each analysis step.
Exercise 30: A/B Testing Framework
Design an experiment to compare two prompting strategies: - Strategy A: Minimal prompts with iterative refinement (start simple, add detail) - Strategy B: Detailed prompts upfront (invest time in the initial prompt)
Define: - What tasks to test with (at least 5 representative coding tasks) - What metrics to measure (at least 3) - How to control for confounding variables - How to determine a statistically meaningful result - What you hypothesize the result will be and why
Exercise 31: Cross-Model Prompt Adaptation
Research or experiment with how the same prompt performs differently across different AI coding assistants (e.g., Claude, ChatGPT, GitHub Copilot, Gemini). Write a report on: - Which aspects of prompts are universal across models - Which aspects need model-specific adaptation - Strategies for writing prompts that work well across multiple models
Exercise 32: Prompt Compression
Take the full five-pillar prompt from the "Connecting the Pillars" section at the end of the chapter. Your challenge: rewrite it to be 50% shorter while maintaining at least 90% of its effectiveness. Explain your compression strategy and which elements you chose to cut and why.
Exercise 33: Adversarial Prompting
Write five prompts that are intentionally designed to produce BAD code from an AI assistant (without being obvious about it). For each adversarial prompt: - Explain the subtle flaw in the prompt - Show what bad code it would likely produce - Show the corrected version that avoids the trap
This exercise builds awareness of how small prompt choices can lead to large quality differences.
Exercise 34: Team Prompt Standards Document
Draft a one-page "Prompt Standards" document for a hypothetical development team. It should include: - Minimum requirements for prompt quality on shared projects - Required information for different types of coding tasks - A checklist developers must complete before submitting a prompt - Examples of acceptable and unacceptable prompts - A process for reviewing and improving team prompts
Exercise 35: The Prompt Engineering Teaching Plan
Design a 60-minute workshop to teach the concepts from this chapter to a team of developers who are new to vibe coding. Include: - An agenda with time allocations - The three most important concepts to teach (and why you chose them) - Two hands-on exercises participants will complete during the workshop - A method for assessing whether participants learned the key skills - Take-home materials for continued practice