AI Test Stack
AI Foundations for QA Professionals/Level 5 — Prompt Engineering
Lesson

Prompt Engineering Fundamentals

Learn prompt anatomy, context, constraints, output format, evaluation, and reusable prompt design for QA work.

10 min read
Prompt fundamentals diagram showing role, task, context, constraints, format, and quality checks.
Prompt fundamentals diagram showing role, task, context, constraints, format, and quality checks.

Overview

Prompt engineering is the practice of turning vague requests into clear, testable instructions that consistently produce useful output. For QA professionals, that makes it one of the most practical AI skills in the whole course.

A good prompt does more than ask nicely. It defines scope, reduces ambiguity, encodes business rules, and shapes the output into something a human or automation pipeline can actually use.

This lesson focuses on the foundations: prompt anatomy, quality patterns, anti-patterns, prompt evaluation, and repeatable prompt design for QA workflows.

A Practical Note for QA Learners

You do not need to become a prompt wizard to benefit from this lesson. The real goal is simpler: learn how to write prompts that are clear enough to test, stable enough to reuse, and structured enough to fit real QA work.

For practical QA work, three things matter most:

  • better prompts produce better first drafts for tests, summaries, and analysis
  • clear constraints reduce hallucinations and invented details
  • evaluation matters just as much as writing the prompt itself

If the topic starts to feel broad, focus on the anatomy template, the good-vs-bad examples, the failure modes, and the hands-on lab.

Learning Goals

  • Explain what makes a prompt clear, bounded, and reproducible.
  • Use a structured prompt template for QA tasks.
  • Identify and fix weak prompt patterns.
  • Evaluate prompt outputs with a practical QA rubric.
  • Create reusable prompt assets for a team-level prompt library.

Core Concepts

1. Prompt Engineering Is Specification Design

A prompt is not just a question. In real engineering work, it behaves more like a lightweight functional specification.

High-quality prompts define:

  • role
  • objective
  • context
  • constraints
  • output format
  • quality checks

That is why prompt quality often determines whether AI output is merely interesting or actually useful.

For QA teams, this matters because vague prompts create vague output, and vague output is difficult to validate.

2. Prompt Anatomy Template

Use this baseline template for most QA tasks:

text
6 lines
1Role:
2Task:
3Context:
4Constraints:
5Output format:
6Quality checks:

Example for QA:

text
6 lines
1Role: You are a senior QA engineer.
2Task: Generate boundary and negative API tests for password reset.
3Context: OTP expires in 10 minutes; account locks after 5 failed attempts; email is the primary identifier.
4Constraints: Do not invent endpoints, fields, or business rules not provided.
5Output format: Markdown table with columns ID, Scenario, Type, Expected Result.
6Quality checks: Include security, retry, expiry, abuse, and lockout behavior.

Why this works:

  • the role anchors tone and perspective
  • the task defines what success looks like
  • the context gives relevant facts
  • the constraints reduce hallucination risk
  • the format makes output reviewable
  • the quality checks widen coverage beyond the obvious cases

3. Good, Better, and Production-Ready Prompts

Weak prompt

text
1 lines
1Give me test cases for login.

Why it fails:

  • no scope
  • no risks
  • no output structure
  • no domain rules

Better prompt

text
1 lines
1Generate positive and negative test cases for login.

Why it improves:

  • task is clearer
  • some coverage expectation exists

What is still missing:

  • business rules
  • explicit constraints
  • reusable structure

Production-ready QA prompt

text
6 lines
1Role: You are a senior QA engineer.
2Task: Generate positive, negative, boundary, and abuse-focused test cases for user login.
3Context: Login supports email and password, MFA is optional, account locks after 5 failed attempts, and successful login redirects to dashboard.
4Constraints: Use only the provided rules. Do not invent APIs, fields, or security features that are not mentioned.
5Output format: Markdown table with ID, Scenario, Category, Preconditions, Expected Result.
6Quality checks: Include validation, authentication failure, lockout, MFA, redirect, and session-handling scenarios.

This version is easier to:

  • review
  • compare across runs
  • reuse in a team prompt library
  • convert into automation or structured documentation

4. Prompt Components That Usually Improve QA Output

ComponentWhat it doesQA example
RoleSets perspective"You are a senior QA engineer"
TaskStates objective"Generate API regression tests"
ContextAdds facts and constraints"OTP expires in 10 minutes"
ConstraintsPrevents unsupported output"Do not invent endpoints"
Output formatMakes response parseable"Return JSON array"
Quality checksExpands real coverage"Include abuse and negative scenarios"

If a prompt is underperforming, one or more of these parts is usually missing or weak.

5. Common Prompt Failure Modes

Prompt failures are often predictable. The most common ones are:

  • missing business constraints
  • ambiguous output format
  • too much irrelevant context
  • no quality checks or acceptance criteria
  • contradictory instructions in the same prompt
  • mixing multiple goals without prioritization

Example:

text
1 lines
1Generate a short but complete summary with all details.

Problem:

  • short and complete can conflict

Better:

text
2 lines
1Generate a concise summary in 5 bullet points.
2Include user impact, root cause, and next action.

6. Prompt Quality Checklist

Before using a prompt in real QA work, ask:

CheckQuestion
Scope clarityIs the task clearly bounded?
Context qualityDoes the model have the right facts?
Constraint qualityHave you prevented likely inventions?
Output usefulnessCan a human or script actually use the result?
QA depthDoes the prompt ask for edge cases, negative cases, and risks?
ReusabilityCould this prompt be used again next sprint?

7. Prompt Iteration Loop

Prompt design is rarely one-shot. Use this loop:

  1. Draft the prompt.
  2. Run it on 3 to 5 varied inputs.
  3. Score the output.
  4. Refine the wording, constraints, or format.
  5. Save the improved version with a version label.

This small loop is what turns prompting from trial-and-error into a repeatable practice.

8. Evaluating Prompt Output

For QA work, a useful output rubric often includes:

CriterionWhat you are checking
Requirement coverageDid the output use the rules you provided?
CorrectnessDid it avoid invented facts and unsupported logic?
Output qualityIs the structure usable and clear?
Risk depthDid it cover negative, boundary, and abuse scenarios?
ReusabilityCan the prompt and output be reused next time?

Prompt engineering without evaluation usually becomes opinion-driven rather than evidence-driven.

9. Prompt Libraries for Teams

Treat good prompts as reusable assets, not personal tricks.

A team prompt library should capture:

  • prompt ID
  • owner
  • use case
  • current version
  • known failure cases
  • example input
  • example good output

Example entry:

FieldExample
Prompt IDQA-API-RESET-001
Use casePassword reset API test generation
Versionv1.3
Known weak spotSometimes misses session invalidation
Output formatMarkdown table

This is especially useful once prompts start feeding automation, CI checks, or shared QA workflows.

QA/SDET Relevance

Manual QA use cases:

  • generate exploratory charters from acceptance criteria
  • expand edge-case lists from user stories
  • summarize bug triage threads into clearer notes
  • turn product ambiguity into clarifying questions

Automation and SDET use cases:

  • generate structured test cases for APIs and UI flows
  • create reusable prompt packs for CI-based AI checks
  • build schema-safe prompts for JSON outputs
  • compare prompt behavior across model upgrades

One practical rule:

  • treat prompts like test assets
  • version them
  • evaluate them
  • keep known failure cases beside them

Practical Work

Exercise: Prompt Makeover Lab

Objective: Turn weak prompts into reusable, production-friendly QA prompts.

Step 1: Collect weak prompts

Take 5 prompts from your own work or use these starter examples:

text
1 lines
1Give me test cases for file upload.
text
1 lines
1Summarize this bug thread.
text
1 lines
1Generate Playwright tests for checkout.

Step 2: Rewrite them using the anatomy template

For each one, fill in:

  • role
  • task
  • context
  • constraints
  • output format
  • quality checks

Step 3: Run old vs new prompts on the same input

Use identical inputs and compare:

  • coverage
  • output structure
  • usefulness
  • hallucination rate
  • QA depth

Step 4: Score both versions

Criterion012
Requirement coveragemisses key rulespartialcomplete
Output clarityambiguousmostly clearunambiguous
Format complianceinvalidmostly validfully valid
QA risk depthshallowmoderatestrong
Reusabilityone-offpartly reusabletemplate-ready

Step 5: Publish your best prompts

Choose the best 3 rewritten prompts and store them in a shared prompt library.

Suggested Hands-On Prompt Scenarios

Try at least 3 of these:

  • Generate boundary-focused API tests for password reset.
  • Generate negative UI tests for profile update validation.
  • Convert acceptance criteria into BDD scenarios.
  • Summarize a long bug thread into triage-ready bullets.
  • Generate a release-risk checklist from a feature description.

Reflection

  1. Which prompt change improved output the most: context, constraints, or format?
  2. Which weak prompt looked acceptable at first but failed under scoring?
  3. What prompt patterns should become team defaults?

Official docs and platform guides

Practical references

Books

  • *Building LLM Powered Applications* by Chip Huyen
  • *Prompt Engineering for Generative AI* by James Phoenix and Mike Taylor

YouTube Resources

Video thumbnail for a prompt engineering beginner course.
Video thumbnail for a prompt engineering beginner course.

What this helps with: A prompt-engineering-first introduction that is much closer to this lesson's focus on instructions, context, examples, and output shaping.

Key Takeaways

  • Prompt engineering is structured specification writing for model behavior.
  • Better prompts combine role, task, context, constraints, format, and quality checks.
  • Prompt quality should be evaluated, not guessed.
  • Reusable prompts are team assets, not one-off chat tricks.
  • For QA teams, good prompting improves both productivity and risk control.

Next Step

Continue with Advanced Prompt Engineering to learn few-shot design, decomposition, critique loops, structured outputs, and prompt robustness patterns for more complex QA workflows.