IntermediateLesson 5 of 10

Prompting Techniques

Master prompt engineering basics for generating accurate, secure, and maintainable code with Copilot.

ELI5 Explanation

A good prompt is like giving clear instructions to a teammate: what to build, rules to follow, and how success looks.

Technical Explanation

Prompt quality improves with structure: role, objective, constraints, input/output format, and validation criteria. For coding tasks, include runtime, framework version, security requirements, and test expectations. Iterative prompting narrows output and improves reliability.

Visual Section

Goal
Constraints
Expected Output
Validation

Hands-on Commands

text
# Prompt template
Role: Senior DevOps engineer
Task: Generate a GitHub Actions workflow for Terraform plan on PR
Constraints: Ubuntu runner, Terraform 1.8, no apply step, fail on fmt/validate errors
Output: Full YAML with comments and secure permissions
Validation: Include required permissions and artifact upload of plan output

Debugging Scenarios

Interview Questions

Beginner

What is prompt engineering?

Designing clear instructions so AI tools produce useful, accurate output.

Why include constraints?

Constraints reduce ambiguity and steer output to valid solutions.

What is a good prompt structure?

Role, task, constraints, desired format, and validation requirements.

Why ask for tests in prompt?

It improves trust by generating verification alongside implementation.

Should prompts include versions?

Yes, versions prevent outdated syntax and dependency mismatch.

Intermediate

How refine a weak first answer?

Point out defects, tighten constraints, request minimal corrected diff.

What are anti-patterns in prompting?

Vague goals, no context, no constraints, and no output format.

How prompt for secure shell scripts?

Require strict mode, input validation, quoting, and safe error handling.

How prompt for maintainability?

Ask for modular functions, comments for complex logic, and naming conventions.

How ensure machine-parseable output?

Specify schema or exact format like JSON/YAML block only.

Scenario-based

Copilot returns invalid YAML repeatedly.

Prompt with expected YAML schema and include a validated example snippet.

Prompt generated dangerous rm command.

Add prohibition constraints and require dry-run plus confirmation checks.

Team prompts are inconsistent across engineers.

Create shared prompt templates for common coding and DevOps tasks.

Output ignores project architecture.

Include folder layout and layering rules in prompt preamble.

How avoid hidden assumptions in generated code?

Ask Copilot to list assumptions before generating final implementation.

Real-world Use Case

An engineering team standardized prompt templates for pipeline generation and reduced failed CI runs by catching missing permissions and syntax mistakes earlier.

Summary

Prompt engineering is the core skill for getting reliable Copilot output: clear intent, explicit constraints, and verification requirements.