Prompt Engineering Lessons from OpenAI

December 28, 2023

How to receive better outputs from the same question rephrased:

  1. Write Clear Instructions (A < B)

    • Example A: Write code to calculate the Fibonacci sequence.
    • Example B: Write a TypeScript function to efficiently calculate the Fibonacci sequence. Comment the code liberally to explain what each piece does and why it's written that way.
      Clear, specific instructions guide the model to provide a more refined and tailored response.
  2. Make the Model Adopt a Persona

    • Example: "You are a psychologist, software developer, or doctor. Act like it using these criteria."
      This approach leverages the model's ability to contextualize the query within the knowledge and framework of the chosen persona, producing more targeted and relevant results.
  3. Break Your Task Into Subtasks

    • Example: "I want you to do this for me in three steps: x, y, and z. Start with x."
      Dividing the task into smaller, manageable parts helps the model focus on individual aspects, improving clarity and output quality.
  4. Provide References for Desired Results

    • Example: Referencing a specific figure, person's work, or attaching files can serve as a benchmark for the model. It allows the model to align its output with the provided reference, ensuring consistency and accuracy.
  5. Define a Context Length

    • Specify a precise context or limit the scope of the task. This ensures the model remains focused and delivers outputs efficiently without unnecessary details or digressions.
  6. Give the Model Time to Reevaluate Its Output (A < B)

    • Example A: "Determine if the student's solution is correct or not."
    • Example B: "First, work out your own solution to the problem. Then compare your solution to the student's solution and evaluate if it is correct or not. Don't decide until you've solved the problem yourself."
      By prompting the model to engage in self-reflection, it generates more thoughtful and accurate outputs.
  7. Ask the Model to Explain Its Reasoning

    • Example: Instead of just asking for an answer, request: "Provide a detailed explanation of how you arrived at the conclusion."
      This not only enhances the quality of the response but also ensures you understand the reasoning process behind it.
  8. Iterate and Refine Your Prompt

    • Experiment with variations of your question to identify the most effective phrasing. Providing feedback to the model (e.g., "Try that again, but focus on XYZ") can further improve the results.
  9. Use Constraints and Parameters

    • Example: "Write an explanation in no more than 150 words."
      Constraints guide the model to tailor the response within the specified limits, enhancing precision and efficiency.
  10. Prompt for Creative Alternatives

    • Example: "Provide three different approaches to solving this problem."
      Encouraging alternative solutions fosters creativity and uncovers new perspectives on a given query.

better prompts