Prompt Engineering Step 5: Zero-Shot vs. Few-Shot Prompting (Copilot)

Understand two fundamental prompting techniques to guide GitHub Copilot more effectively: Zero-Shot (direct instruction) and Few-Shot (providing examples).

Zero-Shot Prompting

This involves giving Copilot Chat a direct instruction or question without providing specific input/output examples within the prompt itself.

  • When to Use: Best for common tasks, general questions, or when using slash commands (/explain, /tests, etc.) where the desired format is somewhat implied by the command.
  • Mechanism: Relies on Copilot's training data and the context provided (open files, #selection, @workspace) to infer the desired output.

Example (Chat):

/explain #selection
Write a python function to calculate the area of a circle given the radius.

Few-Shot Prompting

Here, you provide one or more examples (input -> output pairs) within the prompt to demonstrate the desired pattern, format, or style before making your actual request.

  • When to Use: Effective when you need a very specific output format (e.g., JSON structure, specific comment style), want to teach Copilot a pattern it might not know well, or need to guide its logic for complex transformations.
  • Mechanism: Structure your prompt in Copilot Chat to clearly show the examples first, followed by the final input for which you want an output.

Example (Chat - Sentiment Classification):

Determine if each movie review is Positive or Negative.

Review: "I couldn't stop laughing throughout the film!"
Sentiment: Positive

Review: "The plot was a complete mess and very boring."
Sentiment: Negative

Review: "The cinematography was stunning and the story touched my heart."
Sentiment:

(Copilot should complete the last line with "Positive" based on the examples).

Example (Chat - Code Style/Format):

Convert the following Python comments to the specified format:

Input: # Get user data
Output: // Get user data

Input: # Calculate total price
Output: // Calculate total price

Input: # Validate input parameters
Output:

(Copilot should complete the last line with "// Validate input parameters").

Key Takeaway

Use zero-shot prompting for simpler tasks or when using built-in slash commands. Employ few-shot prompting with clear examples in Copilot Chat when you need to precisely control the output format, style, or logic pattern.