What's changed: New GH-300 Chapter 4 (effective prompts = structure [goal/context/expected output], how Copilot determines context, zero-shot/few-shot, select by relevance; principles & flow = clarity/specificity/iteration/decomposition, input+context→response→refine loop, chat-history use and caveats [irrelevant context/window consumption/new conversation])
4.1Crafting Effective Prompts
Understand prompt structure and how to provide context, how Copilot determines context, zero-shot/few-shot prompting, and best practices for crafting effective prompts.
As Chapter 3 showed, suggestion quality depends heavily on context. Hence prompt engineering—what you convey and how—drives results. A good prompt specifies "the goal, constraints, and expected output format concretely" and supplies sufficient, relevant context. Vague requests yield vague results.
4.1.1Prompt structure and context
An effective prompt includes the goal (what you want), context (the target code, assumptions, constraints), and expected output (language, format, style). In Copilot Chat, explicitly passing a selection or file improves accuracy. For inline suggestions, keeping related code open and writing clear function names/comments first act as "context hints." In short, reduce what the model must guess by supplying needed information up front.
4.1.2How Copilot determines context
Copilot gathers context from around the cursor, open files, and (per feature) related/instruction files (Chapter 3). So users can shape context by opening relevant files, reducing noise, and providing standing conventions via instructions/prompt files (Chapter 2). Since the context window is finite, "selecting relevant information to provide" is more effective than dumping large amounts indiscriminately.
4.1.3Zero-shot and few-shot
Zero-shot gives only instructions, no examples—good for simple, routine tasks. Few-shot shows a few input/expected-output examples first, then asks—effective when you want consistent format/style or to convey a complex/bespoke pattern. For example, "show one test case in this format, then generate other cases in the same format" is few-shot. Choose based on task difficulty and consistency needs.
| Technique | How | Best for |
|---|---|---|
| Zero-shot | Instructions only (no examples) | Simple, routine tasks |
| Few-shot | Show a few input/output examples | Consistent format / complex patterns |
Common: (1) A good prompt = state goal, context, expected output concretely + relevant context (vague in, vague out). (2) Chat: pass a selection/file; inline: open related files / clear names & comments as context hints. (3) Zero-shot = no examples (simple); few-shot = a few input/output examples (consistency/complex). (4) Context is a finite window—select by relevance (better than dumping).
Watch out: (1) "Just a long prompt / lots of context" can backfire—relevance is key. (2) Choose zero-shot vs few-shot by difficulty/consistency (neither is always right). (3) Better prompts do not remove the need to validate output (Chapter 1). (4) Instructions files are standing conventions; prompt files are reusable instructions—distinguish their uses.
4.1.4Section summary
- Good prompt = state goal, context, expected output concretely + relevant context
- Chat: pass a selection/file; inline: open related files and use clear names/comments
- Choose zero-shot (no examples, simple) vs few-shot (examples, consistency/complex)
- Context is a finite window—select by relevance; even with better prompts, validation is required
Sign in to track progress — Log in.
Quick check
(just a quick review)Q1. To enforce a consistent output format/style or a complex/bespoke pattern, which prompting technique is most effective?
Q2. Which combination best represents what an effective prompt should include?
Q3. Which is a correct way to provide context to improve accuracy in Copilot Chat?
Q4. What is the correct correction to "more context is always better"?
Q5. For simple, routine code generation, which technique asks with instructions only, no examples?
Q6. If you craft prompts well, may you skip validating output?
Keep track of your progress
The full study guide is free to read. Sign up free to practice with the question bank, track what you have read, review your mistakes, and highlight passages.

