ChatGPT to NotionChatGPT to Notion

Best Practices Guide for Prompt Engineering (Beginner-Friendly)

on 3 months ago

Best Practices Guide for Prompt Engineering (Beginner-Friendly)

1. Role Explanation

Three roles are involved in prompt application:

  • USER: The user who poses questions or gives instructions
  • ASSISTANT: The model responsible for generating responses
  • SYSTEM: The system role that sets model behavior rules (e.g., defining background logic in API development, or simulating via direct user instructions like "When helping me write, include at least one joke or witty remark in each paragraph")

2. Best Practice 1: Write Clear Instructions

Core Principle

GPT cannot read users' minds. Clearly specify details, formats, roles, etc., to reduce model guesswork.

Specific Strategies

1. Include Detailed Information

  • Target Audience: Beginners
  • Difficulty: ⭐
  • Example:Vague Query: "Recommend a book"Clear Query: "Recommend a communication skills book for career newcomers, published in the past 3 years, with a 豆瓣 score above 8"

2. Assign a Model Role

  • Target Audience: Beginners

  • Difficulty: ⭐

  • Example:

    bash

    SYSTEM: You are a senior book critic USER: Please analyze the core arguments of *Sapiens*

3. Use Delimiters to Separate Content

  • Target Audience: Beginners

  • Difficulty: ⭐

  • Example:

    bash

    USER: Write a poem using the text in triple quotes """Spring slumber ends unawares, where birds sing everywhere"""

4. Break Tasks into Steps

  • Target Audience: Beginners

  • Difficulty: ⭐

  • Example:

    bash

    SYSTEM: Process user input step-by-step Step 1: Summarize the triple-quoted text in one sentence Step 2: Translate the summary into English USER: """Artificial intelligence is a new technical science researching and developing theories, methods, technologies, and application systems for simulating human intelligence"""

5. Provide Example References (Few-Shot Prompting)

  • Target Audience: Beginners

  • Difficulty: ⭐

  • Example:

    bash

    SYSTEM: Answer questions in the same style USER: What is courage? ASSISTANT: Courage is a new shoot breaking through the soil in winter USER: What is hope?

6. Specify Output Length

  • Target Audience: Beginners

  • Difficulty: ⭐

  • Note: When specifying word counts, use a range (e.g., "50-70 words"). Models better control paragraph/bullet counts.

  • Example:

    bash

    USER: Summarize the impacts of climate change in 3 bullet points

3. Best Practice 2: Provide Reference Texts

Core Principle

Avoid model fabrications by providing credible texts to ensure answer accuracy.

Specific Strategies

1. Answer Based on Reference Texts

  • Target Audience: Beginners

  • Difficulty: ⭐

  • Example:

    bash

    SYSTEM: Use the text in triple quotes to answer the question. If no answer is found, write "I could not find an answer." USER: """...(insert article content)""" Question: What are the main conclusions of Einstein's theory of relativity?

2. Cite Text Passages

  • Target Audience: Beginners

  • Difficulty: ⭐

  • Example:

    bash

    SYSTEM: Answer the question using the document and cite passages (format: {"citation": "..."}) USER: """Document content...""" Question: What are the three core arguments mentioned by the author?

4. Best Practice 3: Decompose Complex Tasks

Core Principle

Break complex tasks into simple subtasks to reduce error rates and improve efficiency.

Specific Strategies

1. Intent Classification for Guided Processing

  • Target Audience: Beginners/Professionals

  • Difficulty: ⭐⭐

  • Example:

    bash

    SYSTEM: Classify customer inquiries into primary/secondary categories (JSON format) Primary categories: Technical Support, Billing, Account Management Technical Support secondary categories: Troubleshooting, Device Compatibility USER: My router can't connect to the network

2. Summarize and Filter Long Conversations

  • Target Audience: Professionals/Developers
  • Difficulty: ⭐⭐
  • Scenario: Regularly summarize medical histories in telemedicine, retaining only information relevant to current symptoms.

3. Segment and Summarize Long Documents

  • Target Audience: Professionals
  • Difficulty: ⭐⭐
  • Method: Summarize paragraph by paragraph → Merge paragraph summaries → Recursively generate a full summary to avoid context limits.

5. Best Practice 4: Allow Model "Thinking" Time

Core Principle

Guide the model to reason step-by-step for complex problems to reduce intuitive errors.

Specific Strategies

1. Reason First, Then Judge

  • Target Audience: Professionals/Developers

  • Difficulty: ⭐⭐

  • Example:

    bash

    SYSTEM: Solve the math problem yourself first, then compare with the student's answer USER: Problem: Calculate (17+28)×45 Student's answer: 17×45+28=765+28=793

2. Hide Reasoning Process (Inner Monologue)

  • Target Audience: Professionals/Developers
  • Difficulty: ⭐⭐⭐
  • Scenario: In education, the model generates hints through internal reasoning to avoid exposing answers directly.

3. Check for Omissions

  • Target Audience: Professionals/Developers

  • Difficulty: ⭐⭐⭐

  • Example:

    bash

    USER: List all milestones in AI development from the document ASSISTANT: [Milestone 1, Milestone 2] USER: Are there any omissions? Please check again

6. Best Practice 5: Use External Tools

Core Principle

Leverage external tools to compensate for model limitations (e.g., retrieval, calculation, API calls).

Specific Strategies

1. Embedding-Based Search for Knowledge Retrieval

  • Target Audience: Developers
  • Difficulty: ⭐⭐⭐⭐
  • Principle: Convert text to vectors and match relevant content via cosine similarity (e.g., movie recommendation systems).

2. Code Execution for Complex Calculations

  • Target Audience: Professionals/Developers

  • Difficulty: ⭐⭐⭐

  • Example:

    bash

    SYSTEM: Use Python code to calculate polynomial roots USER: Solve for the real roots of x²-5x+6=0

7. Best Practice 6: Systematically Test Changes

Core Principle

Evaluate model outputs through standardized tests to ensure optimization effectiveness.

Specific Strategies

1. Evaluate Against Reference Answers

  • Target Audience: Professionals/Developers

  • Difficulty: ⭐⭐⭐⭐

  • Example:

    bash

    SYSTEM: Check if the answer includes specified points Points: 1. Armstrong's first moon landing date 2. Mission name USER: """...(answer text)"""

Conclusion

Mastering prompt engineering best practices can significantly enhance AI interaction efficiency. Key strategies include: clarifying instructions, providing context, decomposing tasks, guiding deep thinking, integrating external tools, and systematic testing. For advanced scenarios, further learning of structured prompting techniques is recommended.