Prompt Engineering Best Practices

Daniel Chen
Journey Into AI with Aili

--

Introduction

Welcome to the world of Prompt Engineering, where the right words unlock the full potential of AI! This post is your guide to mastering the art of prompt crafting, inspired by insights from the 2.5-hour “Application Development Using Large Language Models” tutorial led by Andrew Ng and Isa Fulford at NeurIPS on December 11, 2023.

Drawing from the rich content of this tutorial and OpenAI’s document “Six Strategies for Getting Better Results,” we’ve compiled a comprehensive guide to prompt engineering best practices. But we didn’t stop there! Our team has enriched this guide with additional examples and tips, making it not just a summary but a practical handbook for anyone looking to enhance their interactions with AI.

Whether you’re a developer, a content creator, or just an AI enthusiast, this post is tailored to provide you with clear, actionable insights into crafting effective prompts. So, grab a cup of coffee, and let’s dive into the exciting world of prompt engineering — where creativity meets technology, and the possibilities are endless!

Tip 1: Write clear and specific instructions

Perfecting your prompt can dramatically enhance your AI interactions. Here’s a deep dive into each tactic, explaining its benefits and providing detailed, operable examples:

Include Details for Relevance:

  • Reason: The more specific you are, the more tailored the AI’s response will be to your particular need.
  • Benefits: Reduces ambiguity, leading to more accurate and relevant answers.
  • Examples:
    — Vague: “Tell me about World War II.”
    — Detailed: “Explain the causes of World War II, focusing on political tensions in Europe in the 1930s.
    — Vague: “How do I cook rice?”
    — Detailed: “Provide a step-by-step guide to cook Japanese sushi rice in a rice cooker.

Adopt a Persona:

  • Reason: Setting a persona helps the AI adopt a specific tone or style, aligning its responses with your expectations.
  • Benefits: Personalizes the AI’s responses, making them more relevant and engaging.
  • Examples:
    — “Write a brief motivational speech as if you’re a sports coach.”
    — “Explain quantum mechanics like you’re a friendly physics professor speaking to high school students.

Use Delimiters for Clarity:

  • Reason: Delimiters help organize complex prompts, making it easier for the AI to distinguish different parts.
  • Benefits: Enhances the structure and clarity of AI responses.
  • Examples:
    — “Topic: Global Warming — — Questions: Causes, Effects, Solutions.”
    — “Objective: Study Tips — — Subject: Math, Science — — Grade Level: 10th.

Outline the Steps:

  • Reason: Provides a clear structure for the AI to follow, ensuring a complete and systematic response.
  • Benefits: Ensures comprehensive coverage of multi-step processes or queries.
  • Examples:
    — “List the steps to solve a linear equation, starting with isolating the variable.”
    — “Describe the process of photosynthesis in four steps, starting from light absorption.

Provide Examples:

  • Reason: Examples serve as a reference for the AI, guiding the style and format of the response.
  • Benefits: Improves the accuracy and relevance of the AI’s output.
  • Examples:
    — “I need a friendly reminder email. Here’s one I sent before: ‘Hey team, just a quick reminder about tomorrow’s meeting at 10 AM…’”
    — “Create a poem about nature. Example: ‘The gentle breeze whispers through the trees…’

Specify Output Length:

  • Reason: It helps control the verbosity or conciseness of the AI’s response.
  • Benefits: Tailors the response to fit specific requirements or constraints.
  • Examples:
    — “Summarize the plot of ‘To Kill a Mockingbird’ in three sentences.”
    — “Give me a bullet list of five key benefits of meditation.

By integrating these tactics into your prompts, you’re effectively guiding the AI to deliver precise, relevant, and engaging responses that meet your specific needs.

Tip 2: Provide Reference Text

Maximize your AI interactions with well-chosen reference texts. Here’s how to integrate this approach effectively:

Instruct the Model to Answer Using a Reference Text:

  • Tactic: Direct AI to base answers on the provided reference material.
  • Why It’s Effective: Anchors responses in specific information, enhancing accuracy.
  • Example Prompts:
    — Prompt 1: “Based on this article excerpt: ‘Solar panels convert sunlight into electricity, offering a green alternative to fossil fuels. They’re cost-effective over time and increase energy independence,’ explain how solar power is sustainable.
    — Prompt 2: “With this information: ‘Meditation reduces stress, improves concentration, and can lower blood pressure,’ discuss the health benefits of daily meditation.

Instruct the Model to Answer with Citations from a Reference Text:

  • Tactic: Ask AI to include references in its response for credibility.
  • Why It’s Effective: Builds trust and teaches AI to support responses with evidence.
  • Example Prompts:
    — Prompt 1: “Using this study extract: ‘Regular exercise contributes to improved cardiovascular health and longevity,’ answer the question: ‘How does regular exercise benefit long-term health?’ Cite the extract.
    — Prompt 2: “Answer ‘What are the impacts of global warming on polar regions?’ using details from this text: ‘Global warming leads to polar ice melt, rising sea levels, and habitat loss for polar species.’ Include citations.

Incorporating reference texts into your prompts allows you to steer ChatGPT towards more precise and source-backed responses. This is especially useful for academic research, professional inquiries, or any context where detailed, evidence-based information is crucial.

Tip 3: Split Complex Tasks into Simpler Subtasks

Tackling complex tasks can be daunting. Break them down into smaller, more manageable subtasks for better results. Here’s how:

Use Intent Classification for User Queries:

  • Reason: Helps in identifying the core aspects of a user’s query, allowing for targeted and relevant responses.
  • Benefits: Enhances the precision of the AI’s answers and improves user satisfaction.
  • Example Prompts:
    — Prompt 1: “Classify the intent of this query: ‘What should I do if my phone gets wet?’ and provide a step-by-step solution.
    — Prompt 2: “Determine the main intent of ‘How can I improve my website’s SEO?’ and list the top three strategies.

Summarize or Filter Long Conversations:

  • Reason: Keeps dialogue applications focused and prevents them from being overwhelmed by too much information.
  • Benefits: Maintains clarity and coherence in long conversations.
  • Example Prompts:
    — Prompt 1: “Summarize the key points from our previous conversation about renewable energy sources.
    — Prompt 2: “Filter out the main questions asked in our last chat about healthy eating habits.

Piecewise Summary of Long Documents:

  • Reason: Makes processing lengthy documents manageable by summarizing them in sections.
  • Benefits: Creates a comprehensive understanding without overwhelming the AI or the user.
  • Example Prompts:
    — Prompt 1: “Summarize the first three chapters of ‘The Great Gatsby’ and then provide an overall summary.
    — Prompt 2: “Break down and summarize each section of this research paper on climate change, then compile a full summary.

By dividing complex tasks into simpler subtasks, you’re not just simplifying the process — you’re setting the stage for more effective and efficient AI interactions.

You can find us on:

Twitter: @aili_app

Website: https://aili.app

--

--