Practice and reinforce the concepts from Lesson 2
By completing this workshop, you will:
Before we begin, let's establish measurable criteria for prompt effectiveness:
Metric | Description | Measurement Method |
---|---|---|
Accuracy Rate | % of responses that meet requirements | Manual review against checklist |
Completion Time | Time to achieve desired output | Track iterations needed |
Code Quality Score | Adherence to best practices | Linting tools, complexity analysis |
Modification Index | Amount of manual editing required | Lines changed / Total lines |
Reusability Factor | Applicability to similar tasks | Success rate on variations |
Conduct controlled experiments with these prompt pairs:
Test Case 1: Function Generation
Prompt A: "Create a validation function"
Prompt B: "Create a TypeScript function that validates email addresses using regex pattern RFC 5322, returns boolean, includes JSDoc comments, and handles edge cases including null/undefined inputs"
Test Case 2: Debugging Request
Prompt A: "Why doesn't this work?"
Prompt B: "This Express.js middleware throws 'Cannot set headers after they are sent'. Code: [paste code]. Expected: JSON response. Actual: Error. Using Node 18.x, Express 4.x"
Performance Tracking Template:
| Test | Prompt Version | Accuracy | Iterations | Time (min) | Modifications |
|------|----------------|----------|------------|------------|---------------|
| 1 | A | ____% | ____ | ____ | ____ lines |
| 1 | B | ____% | ____ | ____ | ____ lines |
Context: [Technology stack and constraints]
Objective: [Clear, measurable goal]
Requirements:
- Functional: [What it must do]
- Non-functional: [Performance, security, scalability]
- Constraints: [Time, space, compatibility]
Expected Output: [Format, structure, documentation level]
Quality Criteria: [Testing approach, edge cases, error handling]
Real-world Application:
Context: Node.js 18, Express 4.x, PostgreSQL 14
Objective: Create middleware for API rate limiting
Requirements:
- Functional: Limit requests per IP to 100/hour
- Non-functional: <10ms overhead, Redis-backed, horizontally scalable
- Constraints: Compatible with existing auth middleware
Expected Output: TypeScript with full type definitions
Quality Criteria: Unit tests with 90%+ coverage, handles Redis failures gracefully
Environment: [Runtime, version, dependencies]
Symptom: [Observable behavior]
Expected: [Correct behavior]
Code Context: [Relevant code snippet]
Error Details: [Stack trace, logs]
Attempted Solutions: [What you've tried]
Additional Context: [Load, data volume, frequency]
System Context: [Current architecture overview]
Challenge: [Specific problem to solve]
Constraints: [Technical, business, regulatory]
Scale Requirements: [Users, data, transactions]
Success Metrics: [How to measure success]
Exercise: Optimize a Database Query Prompt
Start with this basic prompt and improve it through iterations:
Baseline Prompt: "Make this query faster"
Iteration Tracking Sheet:
| Iteration | Prompt | Response Quality | Actionable? | Benchmark Improvement |
|-----------|--------|------------------|-------------|----------------------|
| 0 | "Make this query faster" | Generic advice | No | N/A |
| 1 | [Your improved version] | | | |
| 2 | [Further refined] | | | |
| 3 | [Production-ready] | | | |
Target Metrics:
You're tasked with building a product recommendation engine. Let's craft prompts for each phase:
Context: E-commerce platform with 100k+ products, 10M monthly users
Task: Design a recommendation algorithm
Constraints:
- Response time < 200ms
- Must handle sparse data (new users/products)
- GDPR compliant
- Budget for infrastructure: $5000/month
Output needed: Technical specification with algorithm choice justification
Based on the recommendation to use collaborative filtering with matrix factorization:
- Provide Python implementation using surprise library
- Include data preprocessing pipeline
- Design caching strategy for predictions
- Create API endpoint structure (FastAPI)
- Include monitoring and A/B testing setup
Format: Production-ready code with comprehensive error handling
Current implementation details:
- Algorithm: SVD with 100 factors
- Training time: 6 hours on 10M ratings
- Prediction time: 180ms average
- Memory usage: 8GB
- Accuracy: RMSE 0.92
Requirements:
- Reduce training time by 50%
- Maintain or improve accuracy
- Keep prediction time under 200ms
Provide: Specific optimization techniques with expected impact
Situation: Provide context and environment Task: Define the specific objective Action: Specify required steps or constraints Result: Describe expected output format
Example:
Situation: Microservices architecture with 20+ services experiencing cascading failures
Task: Implement circuit breaker pattern
Action: Use Hystrix/Resilience4j, configure for 50% error threshold, 10-second timeout
Result: Java Spring Boot implementation with unit tests and configuration guide
Track your prompt effectiveness with this scoring system:
Criterion | Weight | Score (1-5) | Weighted Score |
---|---|---|---|
Clarity | 20% | ___ | ___ |
Completeness | 25% | ___ | ___ |
Technical Accuracy | 20% | ___ | ___ |
Actionability | 20% | ___ | ___ |
Efficiency | 15% | ___ | ___ |
Total Score | 100% | ___/5.0 |
Scoring Guide:
Get AI to create exactly this output using the most efficient prompt:
*****
* *
* T *
* *
*****
Create prompts that generate:
Create a prompt that makes AI:
Craft a prompt for this scenario: "You're building an e-commerce site and need a function that calculates shipping costs based on weight, distance, and delivery speed. Include international shipping considerations."
Document:
Based on your experiments, complete these principles:
Clarity: Good prompts are _____________ and avoid _____________
Context: Always include _____________ about your _____________
Specificity: The more _____________ you are, the better _____________
Iteration: First prompts are rarely perfect; always be ready to _____________
Design templates for common scenarios:
Bug Fixing Template:
I have a [language] [type of program] that should [expected behavior].
Instead, it [actual behavior].
Here's the code: [code]
Error message (if any): [error]
What I've tried: [attempts]
Learning Template:
[Your template here]
Code Generation Template:
[Your template here]
Optimization Template:
[Your template here]
Conduct this experiment:
Research and document advanced prompt patterns:
Write a one-page guide for future students with:
Write optimized prompts for these real-world scenarios:
Startup MVP: "I need to quickly prototype a booking system for a small yoga studio"
Student Project: "I'm learning web development and need to create my first portfolio website"
Professional Task: "I need to refactor legacy code to modern standards"
Problem Solving: "Our application is running slowly with large datasets"
For each scenario, create:
Your submission should include:
💡 Remember:
Next lesson, you'll put your prompt engineering skills to work generating complete applications with AI assistance. Start collecting prompts that work well - you'll need them!