Most advice on prompting AI coding tools boils down to "be specific." That's true, and not very helpful, because it doesn't tell you what specific looks like.
Here's a structure that does: Gherkin. Yep, the old Given / When / Then. pattern.
I don't mean writing test scenarios, and I don't mean setting up a BDD framework. I mean borrowing the shape of a Gherkin scenario to write the request you give your AI tool, so the request can't leave out the things that matter.
Why vague prompts go wrong
Here's a typical request:
Add discount code support to checkout.
The AI now has to guess a lot. Where do the codes come from? Which page does the user enter them on? What triggers the discount being applied? What does "applied" mean on screen? Every gap gets filled with an assumption, and you only find out which ones were wrong after reading the code.
Given/When/Then happens to ask for exactly the three things that vague requests tend to skip:
- Given: the starting state. What exists already: data, pages, user state.
- When: the trigger. What the user or system does.
- Then: the outcome. What should be observably true afterwards.
An example
Given I have a valid code from the "DiscountCodes" table When I enter that code into the "Coupons" page And I click "Apply" Then the price updates according to the specified discount Look at what that already pins down:
- Where the data lives: the
DiscountCodestable - Where the interaction happens: the
Couponspage - What triggers the behaviour: clicking
Apply - What the result is: the price changes
That's four decisions the AI no longer has to guess, in four lines.
Naming real things is a feature
If you've written test scenarios, you may have been taught to keep them declarative and avoid mentioning UI details. That's good advice for tests, which should survive a redesign.
A development prompt has a different job. You want the AI anchored to your actual codebase. Table names, page names, button labels, and existing services all tell it where to put things and what to reuse, rather than inventing its own structure.
So use the real names. The scenario is a brief for building something, not a long-lived test.
Tightening it up
Look again at the last line of the example: "the price updates according to the specified discount." That's the weakest part. Specified where? In which column? Is it a percentage or a fixed amount?
Spelling it out gives the AI something it can't misread:
Given a basket totalling £100.00 And a code "SAVE10" in the "DiscountCodes" table with DiscountType "Percentage" and Value 10 When I enter "SAVE10" into the "Coupons" page And I click "Apply" Then the basket total displays £90.00 Concrete values do two jobs. They remove ambiguity, and they give you an easy check afterwards: either the page shows £90.00 or it doesn't.
One scenario is a start, not a spec
The happy path is the one the AI will build anyway. The value comes from writing down the cases it wouldn't think of:
Given a code "OLDCODE" in the "DiscountCodes" table that has expired When I enter "OLDCODE" into the "Coupons" page And I click "Apply" Then the basket total is unchanged And I see the message "This code has expired" Given I have already applied the code "SAVE10" When I enter "SAVE20" into the "Coupons" page And I click "Apply" Then only "SAVE20" is applied Writing these forces decisions you'd have had to make eventually: do codes stack, or does the second replace the first? Is an expired code silently ignored, or does it show an error? Written down, those decisions are yours. Left out, the AI makes them for you and doesn't mention it.
What Given/When/Then doesn't cover
The format describes behaviour. It doesn't describe how to build it, so add a short constraints block for that:
Implement the behaviour described above. Constraints: - Use the existing repository pattern for data access. - Don't change the schema of DiscountCodes without asking me. - Don't add behaviour that isn't covered above without telling me. - If anything above is ambiguous, ask me rather than guessing. Scenarios describe what. Constraints describe how, and what not to touch. Together they make a much tighter brief than either alone.
Where this falls short
- It only covers what you thought of. The AI can match every scenario and still get an unlisted case wrong. Review the output and try to break it.
- It's about behaviour, not quality. Nothing here covers performance, security, or maintainability.
- It doesn't suit every task. Refactors, performance work, and visual polish don't fit the format well. Use it where the work is "when X happens, Y should result."
- Don't over-specify the implementation. If your Given/When/Then starts dictating method names and class structure, you've stopped describing behaviour and started writing the code in English.
A side benefit
If you write requests this way, you end up with something that's one short step from an acceptance test. The same scenarios can later become real BDD scenarios if you want them to, without you having to rewrite the thinking.
It also happens to be a format testers already write fluently. If your QA is the person on the team best at saying precisely what "correct" looks like, this is a good place to let them lead.
Try it
Next time you're about to type a one-line request into your AI tool, stop and write three lines first: the starting state, the trigger, the expected outcome. Then add the awkward case you'd normally only think of after something broke.
See what comes back. Then notice which lines you had to change, because those are the places your own idea of the feature was fuzzier than you thought.
I'm a test automation architect, and the author of The Automation Trap. I maintain a AI workflow tool called 'SignalBox' and a MCP sdk for C# called *
ZeroMcp.net*
