Prompt engineering is the process of optimizing text input to a language model to guide its behavior and improve the quality of its output.

Core Techniques

  • Zero-shot Prompting: Asking the model to perform a task without providing any examples.
  • Few-shot Prompting: Providing a few examples of input-output pairs to demonstrate the desired behavior.
  • Chain-of-Thought (CoT): Encouraging the model to 'think step-by-step' to solve complex reasoning problems.
  • System Prompts: Setting the high-level behavior or 'persona' of the model (e.g., 'You are a helpful coding assistant').
cot_example.txttext
User: If I have 3 apples and I buy 2 more, then eat 1, how many do I have?
      Let's think step-by-step.

Model: 1. You started with 3 apples.
       2. You bought 2 more, so 3 + 2 = 5 apples.
       3. You ate 1, so 5 - 1 = 4 apples.
       Final answer: 4

Best Practices

  • Be specific and clear about the desired output format.
  • Provide context and constraints (e.g., 'Summarize in 50 words').
  • Use delimiters like triple quotes or XML tags to separate instructions from content.
  • Iterate and refine prompts based on model responses.