Skip to main content
In this lesson we cover the foundations of prompt engineering: how to write clear, targeted instructions that steer AI assistants (like GitHub Copilot) to produce correct, project-appropriate code. Think of prompt engineering as explaining a task to a new teammate—except you must be mindful of how large language models interpret context, constraints, and examples.
A dark blue presentation slide with the KodeKloud logo titled "Foundations of Prompt Engineering." The subtitle reads "Getting the Desired Results From GitHub Copilot."
Why prompt engineering matters
  • Your objective is to get code (or other outputs) that are correct, maintainable, and aligned with project needs.
  • Unlike traditional programming—where you write the implementation—prompt engineering focuses on guiding the assistant to produce the implementation.
  • Small differences in phrasing can change whether the assistant returns a generic suggestion or a solution tailored to your codebase and conventions.
Microsoft popularized a concise guideline called the Four S’s: Single, Specific, Short, and Surround. These principles are particularly useful when working with coding assistants and often appear in related certification materials.
The Four S’s provide a short, high-utility checklist for crafting prompts that produce clearer, more reliable AI outputs.
The Four S’s explained Keep prompts single-focused
  • Aim for one clearly defined task per prompt, like a function with a single responsibility.
  • Combining unrelated requests increases the chance of incomplete or conflicting suggestions.
A presentation slide titled "The Four S's of Prompt Engineering" showing four numbered tiles: 01 Single, 02 Specific, 03 Short, and 04 Surround. The first tile is highlighted in blue with explanatory text, and each box includes a simple icon.
Be specific
  • The more explicit you are about functional requirements, edge cases, performance constraints, and acceptance criteria, the more likely the model will deliver actionable code.
  • Include framework names, expected inputs/outputs, error handling, and style guidelines when relevant.
Keep prompts short (but complete)
  • Concise prompts are easier for the model to process without truncation.
  • Remove irrelevant detail but keep essential constraints and examples.
Surround: provide ambient context
  • Make surrounding code and project context available: file names, nearby components, and related tests.
  • When the assistant can “see” related files, it is more likely to generate suggestions that fit your codebase and naming conventions.
  • Use descriptive file names to help the model infer intent and scope.
Clarity, context, and comments
  • Build prompts on the Single and Specific principles by giving explicit instructions that minimize ambiguity.
  • Use comments in code to provide business rules, expected data shapes, and how a change should integrate with the larger system—these act as guideposts for the assistant.
A dark-themed slide titled "Clarity and Context" displaying four numbered panels with icons. The panels list tips: 01 Build on single/specific principles, 02 Provide explicit instructions, 03 Include relevant contextual details, and 04 Use comments to give additional context.
Examples and iteration
  • Provide concrete examples (code snippets, input/output pairs, or pseudocode) so the model can pattern-match expected structure and behavior.
  • Treat the interaction as a dialogue: inspect the assistant’s response, give targeted feedback, and iterate until results match expectations.
  • Continuously enrich prompts and inline comments with lessons learned during development—this creates stronger, persistent context for future suggestions.
A dark presentation slide titled "Examples and Iteration" with four numbered panels and icons. Each panel gives a tip: use examples, treat responses as dialog, iterate/refine prompts, and enrich comments with details.
Prompting approaches: zero-shot, one-shot, and few-shot Choose an approach based on task complexity and the consistency you need. Below is a concise comparison to help you pick: Zero-shot
  • You give only a description of the task and rely on the model’s pretraining to infer the solution.
  • Works well for standard, widely-known algorithms or formatting tasks.
Example prompt (zero-shot)
A typical result the model might generate:
A diagram titled "Zero-Shot Learning" showing a flowchart where a user's natural-language prompt is processed by an AI model/LLM (through a prompting process) that uses pre-trained knowledge to generate responses and produce a final output. The graphic emphasizes the AI infers intent without needing specific examples.
One-shot
  • Supply a single example that demonstrates the desired mapping or format along with the task description.
  • Useful when one representative example clarifies ambiguous requirements.
Example one-shot prompt
The single example helps the model generalize more accurately.
A flowchart titled "One-Shot Learning" showing a user providing a single example to an AI model, which processes that example and learns its structure. The AI then generates responses and produces a final output influenced by the given example.
Few-shot
  • Provide multiple examples to establish a consistent pattern, style, or error-handling strategy.
  • Best when you need predictable, repeatable outputs that adhere to specific conventions.
Example few-shot prompt
Multiple examples help the model detect patterns reliably and follow the intended logic.
A flowchart titled "Few-Shot Learning" showing how user-provided examples are fed into an AI model/LLM that processes examples, detects patterns, and performs inference/generation. The diagram ends with the model producing responses that balance unpredictability and precision.
Best practices summary Clarity & context
  • Keep prompts single-focused and specific.
  • State framework, coding standards, performance goals, and accessibility requirements when relevant.
  • Use in-code comments to document business logic, expected inputs/outputs, and integration points.
Examples & iteration
  • Provide examples whenever possible (one or more) to communicate the desired pattern or style.
  • Treat model outputs as a draft: iterate with focused feedback to converge on the final solution.
  • Enrich prompts and comments over time so future interactions benefit from accumulated context.
Practice and measurement
  • Experiment with zero/one/few-shot approaches to learn which works best for each task type.
  • Track which prompt patterns consistently produce high-quality suggestions and codify them as templates for your team.
Further reading and references
  • GitHub Copilot documentation
  • Microsoft guidance on prompt engineering principles and assistant UX (search for “Four S’s prompt engineering”)
Practice these techniques in real projects to develop an intuition for phrasing, context, and example selection—over time you’ll get faster, more reliable outputs from AI assistants.

Watch Video