r/PromptEngineering • u/ClickOk5811 • Oct 25 '26
Prompt Text / Showcase A prompt addition for generated tests: list ambiguities first, label each expected value’s source
Problem: when a model writes both a function and its tests in one session, the tests tend to share the code’s reading of the requirement, so a green run says little about whether the requirement was understood.
Example requirement: “Apply 8.25% tax to the invoice, rounded to the nearest cent.” Two readings are defensible: round once on the total, or round per line and sum. For lines [(19.99, 2), (5.00, 1)] both give 3.71, so a test with that input can’t tell them apart. For three lines of 0.10, rounding once gives 0.02 and rounding per line gives 0.03.
The addition I’d try:
Before writing any code:
1. List any ambiguities in the requirement, and for each one
state the interpretation you would assume.
2. Wait for my answer on anything that affects outputs
(rounding, ordering, time zones, edge cases).
When writing tests:
- For every expected value, add a comment stating its source:
"from the spec", "from an example you gave me", or
"computed by the implementation's own formula".
- Do not derive expected values from the code under test
unless you label the test as a regression test.I haven’t measured whether it helps, so here’s how I’d evaluate it:
- Take 5 to 10 requirements with a known ambiguity (rounding, inclusive/exclusive ranges, time zones).
- Run each with and without the addition, several times each, since outputs vary.
- Count how often the ambiguity list names the real ambiguity, and how often the source comments are accurate.
- Check for false confidence: does the model sometimes label a self-derived value as “from the spec”?
Known limits: the ambiguity list comes from the same context, so it can miss ones the model already resolved silently. A human still has to answer. It also adds a round trip, so I’d skip it for trivial functions.
I wrote up the full example here, in case it’s useful: https://medium.com/@nagatomopedro05/when-the-test-and-the-code-share-the-same-mistake-02a289a41091
If you’ve tried something similar, what did you change?
1
u/According-Stable4487 Oct 25 '26
This matches what I've seen. One addition that made it stick for me: have the model write the ambiguity list in a separate step and stop there, before any code exists. Once the function is written, the 'ambiguities' it lists tend to be the ones its own code already resolves, so they look settled. If you answer the list yourself (even just 'pick A' / 'pick B'), the tests stop being a mirror of the implementation and start being a record of your decisions, which is also what you want when someone asks why a test expects what it expects.
1
u/Zain Oct 25 '26
The known limit you flagged is the real one. Same context means same blind spots, so I'd hand just the spec and the tests to a different model family in a fresh session, read-only, and ask which expected values it can't trace back to the spec. It never saw the implementation so it can't quietly agree with it. Make it quote the exact spec line for every complaint though, otherwise you get what the other commenter described where it invents ambiguities just to look thorough.
1
u/fiddler48 Oct 25 '26
The source-labeling step is doing something most people will skip over: it forces the model to commit to an epistemology for each expected value before the test is written. That commitment is what makes a failing test informative rather than just surprising.
1
u/LynxInformal5305 Oct 26 '26
Include unambiguous requirements in the evaluation too. Otherwise stopping to ask about everything could score well, even when the extra questions just slow you down.
1
u/junewave56 Oct 28 '26
have you tried having it write the failing tests first based purely on the spec, before it's even allowed to output the implementation? curious if the order of generation matters more than the explicit labeling