Blog

    AI Prompt Engineering for QA: Generating Test Cases with an LLM and the Review Gate Before the Suite

    By GauravSeptember 18, 20269 mins read
    On this page

    AI prompt engineering for QA is the practice of writing prompts that make a large language model draft useful test cases from requirements, user stories or API specifications. The drafts arrive fast, but some are wrong in ways that look right, so the value depends on a review gate before any generated test enters the suite.

    Startup founders, engineering leaders and QA leads will find how to write prompts that produce checkable cases, what the review gate checks and how to keep generated tests from weakening the suite.

    What is AI prompt engineering for QA?

    AI prompt engineering for QA means giving a large language model a requirement, its context and a strict output format so it drafts test cases a tester can check. The model proposes; a person reviews each case against the requirement before it is added to the regression suite or automated.

    Want generated tests without a weaker suite?

    We set up LLM test drafting with a review gate and traceability to requirements.

    NIST's Generative AI Profile (NIST AI 600-1, July 2024) defines confabulation as the production of confidently stated but erroneous or false content, known colloquially as hallucinations or fabrications, and says confabulations also include outputs that diverge from the prompt or contradict earlier statements in the same context.

    In test generation, confabulation looks like an expected result the requirement never stated, a field the API does not have, or a boundary value chosen from thin air. Each of these can pass review if the reviewer only skims, which is why Agnotic Technologies treats the gate as the core of the process.

    Why use an LLM to draft test cases?

    An LLM helps draft test cases because it covers the obvious paths quickly and suggests variations a tired tester might skip. It does not know your system, so its value is in the first draft, not the final word.

    • Coverage prompts: listing negative, boundary and permission cases for each requirement.
    • Consistency: every case in the same format, with preconditions, steps and expected results.
    • Volume: drafting cases for a long list of similar API endpoints or form fields.
    • Fresh eyes: proposing scenarios from the wording of a requirement rather than from how the code works.

    How do you write a prompt that produces checkable test cases?

    You write a prompt that produces checkable test cases by giving the model the requirement text, the relevant data rules and a fixed output structure, and by telling it to mark anything it had to assume.

    • Step 1, context: paste the requirement or user story, its acceptance criteria and the field definitions it refers to.
    • Step 2, scope: ask for named case types, for example positive, negative, boundary and role-based access.
    • Step 3, format: require one case per item with an ID, the requirement ID it traces to, preconditions, steps, test data and expected result.
    • Step 4, assumptions: instruct the model to list any assumption separately instead of building it into an expected result.
    • Step 5, no invention: tell it to leave the expected result blank when the requirement does not say what should happen.

    Keep prompts in version control next to the tests they produce. When a prompt changes, the team can see which generated cases came from which version.

    What does the review gate check?

    The review gate checks that each generated case traces to a real requirement, that its expected result is stated or implied by that requirement, and that it adds coverage the suite does not already have.

    FDA's General Principles of Software Validation guidance says a software product should be challenged with test cases based on its internal structure and with test cases based on its external specification, and that test plans should identify the test cases, with their inputs, procedures, outputs and expected results.

    • Traceability: the requirement ID exists and the case actually tests it.
    • Expected result: it matches the requirement or a documented rule, not the model's guess.
    • Test data: values are synthetic and valid for the system, with no real patient data.
    • Duplication: the case is not a reworded copy of an existing test.
    • Assumptions: every listed assumption is confirmed with the product owner or removed.

    A reviewer who rejects a case records why. Over a few cycles, those reasons show which prompt instructions need tightening.

    Where should generated tests never go straight in?

    Generated tests should never go straight into areas where a wrong expected result causes harm or hides a defect. In those areas, the gate needs a second reviewer with domain knowledge.

    • Dosing, units and clinical calculations, where a plausible wrong value is the most dangerous kind.
    • Access control, where a case that expects too much access teaches the suite to accept a leak.
    • Billing and claims rules, where payer logic is specific and rarely written down in full.
    • Regulated features, where test records may be read by auditors.

    Keeping patient data out of prompts

    Patient data stays out of prompts when test data is synthetic from the start and the prompt holds only requirements and schemas. Never paste production records into a model to get realistic cases.

    • Use synthetic data generators or hand-written fixtures for names, dates and identifiers.
    • Send schemas and field rules, not sample rows from production.
    • Check the model provider's data retention terms before sending internal documents.
    • Log prompts and outputs so a reviewer can see exactly what the model was given.

    Prompts for different test levels

    Prompts work differently at each test level, so keep a template per level rather than one prompt for everything.

    • Unit level: give the function signature and its rules, and ask for input and output pairs.
    • API level: give the specification for one endpoint, and ask for request and response cases, including the error codes the specification lists.
    • End to end: give the user story and screens, and ask for scenarios with steps a tester can follow.

    From approved case to automated test

    Once a case passes review, it becomes a manual test, an automated test or both. Automation is where a second kind of error creeps in, so generated test code goes through the same gate.

    • Automated tests are written or generated from the approved case, not from the original prompt.
    • Each automated test keeps the case ID and requirement ID in its name or metadata.
    • A new test must fail when the behavior it checks is broken, so run it against a deliberately broken build.
    • Flaky generated tests are fixed or removed, never retried until green.

    Measuring whether generation helps

    Measuring whether generation helps means looking at defects found and review effort, not at how many cases the model wrote.

    • Acceptance rate: the share of drafted cases that pass review, tracked per prompt version.
    • Rejection reasons: invented results, duplicates and missing traceability, counted separately.
    • Defects found: issues caught by generated cases that existing tests missed.
    • Reviewer time: how long review takes compared with writing cases by hand.

    What goes into a test-drafting prompt?

    A test-drafting prompt holds six parts, each filled from your requirement tool rather than typed freehand, so the model's job stays narrow.

    Parts of a test-drafting prompt
    Prompt partWhat it containsWhy it is there
    Role and taskDraft test cases for one requirement, in a fixed formatStops the model from writing code or prose
    RequirementID, text and acceptance criteriaGives the only source for expected results
    Data rulesField types, allowed values and limitsLets the model choose valid boundary values
    Case typesPositive, negative, boundary and access casesAsks for the coverage the team actually wants
    Output formatCase ID, requirement ID, steps, data, expected result and assumptionsMakes each case easy to review and import
    ConstraintsNo real patient data, and a blank result when the requirement is silentBlocks the most harmful errors before review

    A worked example: an appointment booking requirement

    A worked example: a requirement says a patient can book only an open slot, at least a set time ahead, and only with clinicians at their registered practice.

    • The model drafts positive cases for a valid booking, boundary cases at the minimum notice time and negative cases for a full slot.
    • It also proposes a case where a patient books with a clinician at another practice, expecting an error message with specific wording.
    • The reviewer keeps the first three groups, then checks the error wording. The requirement does not specify it, so the expected result becomes a rejected booking with no wording check.
    • The reviewer adds a case the model missed: two patients trying to book the last slot at the same moment.
    • Approved cases go into the test management tool with the requirement ID, and the concurrency case is flagged for automation.

    The review kept the model's coverage, removed one invented detail and added one case only a person who knows the system would think of. That is exactly what the gate is for.

    Who owns the prompts and the gate?

    Named owners keep the process from drifting. Without them, prompts get edited ad hoc and the review standard slips.

    • QA lead: owns prompt templates and the review checklist.
    • Product owner: answers assumption questions and confirms expected results the requirement leaves open.
    • Domain reviewer: signs off cases in clinical, billing and access-control areas.
    • Engineering: owns automation of approved cases and keeps traceability fields intact.

    What are the common mistakes with AI prompt engineering for QA?

    The common mistakes with AI prompt engineering for QA come from trusting fluent output and measuring the wrong thing.

    • Counting cases: a larger suite is reported as better coverage even when many cases overlap.
    • Accepting invented results: expected outcomes the requirement never stated become the new truth.
    • Skimming review: reviewers approve batches instead of single cases.
    • Losing traceability: generated cases have no requirement ID, so nobody can tell what they cover.
    • Real data in prompts: production records are pasted in for realism.

    What does LLM test drafting mean for your build plan?

    Adding LLM test drafting changes the QA workflow more than the tooling. Plan reviewer time, prompt maintenance and traceability fields first.

    • Make sure requirements have IDs and acceptance criteria the model can read.
    • Decide which areas need a second domain reviewer.
    • Add case ID and requirement ID fields to the test management tool if they are missing.
    • Track rejected cases and reasons to improve prompts.

    How does Agnotic set up LLM-assisted test design?

    Agnotic sets up LLM-assisted test design for QA teams: prompt templates tied to your requirements, a review gate with traceability, synthetic test data and automation of approved cases in your existing framework.

    Faster test design with a gate that holds

    Prompt templates, review rules and traceable automated tests.

    Sources

    Frequently Asked Questions

    Founders, engineering leaders and QA leads who want to draft test cases faster with a large language model without letting unreviewed or invented expectations into their regression suite.

    Talk to an engineer about your project

    Share a sample of your requirements and current test cases. We will show how drafting and review would fit your QA workflow.