// projects.prompt-engineering
10 Best Prompt Engineering Projects
Hand-picked and ordered easiest → hardest — each with complete code and expected output. Build these to turn lessons into a portfolio.
Back to Prompt Engineering course
// solution.code
ai
# Recipe Generator Prompt Engineering Solution
# This demonstrates basic prompt structure and output constraints
# Example prompt template for an LLM API call
def generate_recipe_prompt(ingredients, dietary_restrictions=None, cuisine_type=None):
"""
Creates a structured prompt for recipe generation with constraints.
Args:
ingredients: List of available ingredients
dietary_restrictions: List of dietary constraints (e.g., vegan, gluten-free)
cuisine_type: Optional cuisine preference
"""
# Base prompt with clear instructions
prompt = """You are a professional chef. Generate a complete recipe using the ingredients provided.
AVAILABLE INGREDIENTS:
"""
# Add ingredients list
prompt += "\n".join(f"- {ingredient}" for ingredient in ingredients)
# Add dietary restrictions if provided
if dietary_restrictions:
prompt += "\n\nDIETARY RESTRICTIONS (MUST FOLLOW):\n"
prompt += "\n".join(f"- {restriction}" for restriction in dietary_restrictions)
# Add cuisine preference if provided
if cuisine_type:
prompt += f"\n\nCUISINE TYPE: {cuisine_type}"
# Specify output format constraints
prompt += """\n\nOUTPUT FORMAT:
1. Recipe Name
2. Servings
3. Prep Time & Cook Time
4. Ingredients with measurements
5. Step-by-step instructions
6. Nutritional highlights
IMPORTANT: Use ONLY the ingredients listed above. Keep instructions clear and concise."""
return prompt
# Example usage
ingredients = ["chicken breast", "bell peppers", "onions", "garlic", "olive oil", "rice"]
dietary_restrictions = ["gluten-free", "low-sodium"]
cuisine = "Mediterranean"
# Generate the prompt
recipe_prompt = generate_recipe_prompt(ingredients, dietary_restrictions, cuisine)
print("=== RECIPE GENERATOR PROMPT ===")
print(recipe_prompt)
print("\n=== PROMPT SENT TO LLM ===")
print("\n[This prompt would be sent to an LLM API like GPT-4, Claude, etc.]")
print("\nKey Prompt Engineering Techniques Used:")
print("✓ Clear role assignment (professional chef)")
print("✓ Structured input sections (ingredients, restrictions)")
print("✓ Explicit constraints (must use only listed ingredients)")
print("✓ Defined output format (numbered sections)")
print("✓ Emphasis keywords (MUST FOLLOW, IMPORTANT, ONLY)") output
=== RECIPE GENERATOR PROMPT === You are a professional chef. Generate a complete recipe using the ingredients provided. AVAILABLE INGREDIENTS: - chicken breast - bell peppers - onions - garlic - olive oil - rice DIETARY RESTRICTIONS (MUST FOLLOW): - gluten-free - low-sodium CUISINE TYPE: Mediterranean OUTPUT FORMAT: 1. Recipe Name 2. Servings 3. Prep Time & Cook Time 4. Ingredients with measurements 5. Step-by-step instructions 6. Nutritional highlights IMPORTANT: Use ONLY the ingredients listed above. Keep instructions clear and concise. === PROMPT SENT TO LLM === [This prompt would be sent to an LLM API like GPT-4, Claude, etc.] Key Prompt Engineering Techniques Used: ✓ Clear role assignment (professional chef) ✓ Structured input sections (ingredients, restrictions) ✓ Explicit constraints (must use only listed ingredients) ✓ Defined output format (numbered sections) ✓ Emphasis keywords (MUST FOLLOW, IMPORTANT, ONLY)
