AI Does Not Fix Vague Thinking: How to Write Specifications You Can Verify

When an AI assistant gives you a wrong answer, the instinct is to blame the model. Often the real cause is the request. This article shows how to turn a vague request into a specification you can check, using a C# example.
Why vague requests fail
A language model produces the most plausible continuation of the context you give it. If the context leaves out the goal, constraints, or acceptance criteria, the model fills those gaps with common defaults. The output can read well and still be wrong for your system.
Take the request: "Write a method that validates an email address."
Questions the request leaves open:
- Should it check format only, or also whether the domain accepts mail?
- Should it accept internationalised addresses?
- What should it return for null, empty, or whitespace?
- Is the result a boolean, or a structured error?
- Is it called on a hot path where allocation matters?
The model will pick answers for all five. You will not know which unless you read carefully.
Step 1: Write the contract before the code
A good specification names inputs, outputs, failure behaviour, and constraints. Here is a version of the request that carries that information.
Goal: Validate the email field of a registration request.
Input: string that may be null or whitespace.
Output: a result with IsValid and a machine readable ErrorCode.
Rules:
1. Null, empty, or whitespace returns ErrorCode "Required".
2. Length above 254 characters returns "TooLong".
3. Must contain exactly one "@" with non empty text on both sides.
4. Do not attempt DNS or network calls.
Constraints: no external packages, no exceptions for invalid input.
This is useful to a human reviewer as well as to a model. It makes the intended behaviour explicit.
Step 2: Turn the contract into tests first
The strongest way to check AI generated code is a test suite you wrote from the specification, before seeing the implementation. The tests become the oracle.
public sealed record EmailValidationResult(bool IsValid, string? ErrorCode);
public static class EmailValidator
{
public static EmailValidationResult Validate(string? value)
{
// Implementation under review
throw new NotImplementedException();
}
}
using Xunit;
public class EmailValidatorTests
{
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public void Missing_value_returns_Required(string? input)
{
var result = EmailValidator.Validate(input);
Assert.False(result.IsValid);
Assert.Equal("Required", result.ErrorCode);
}
[Fact]
public void Value_over_254_characters_returns_TooLong()
{
var input = new string('a', 250) + "@x.com";
var result = EmailValidator.Validate(input);
Assert.Equal("TooLong", result.ErrorCode);
}
[Theory]
[InlineData("a@b")]
[InlineData("first.last@example.com")]
public void Well formed_values_are_valid(string input)
{
Assert.True(EmailValidator.Validate(input).IsValid);
}
[Theory]
[InlineData("@example.com")]
[InlineData("user@")]
[InlineData("a@b@c")]
public void Malformed_values_are_invalid(string input)
{
Assert.False(EmailValidator.Validate(input).IsValid);
}
}
Now you can ask the assistant for an implementation and run the suite. A failing test is concrete feedback you can paste back into the conversation.
Step 3: Test the properties, not only the examples
Example tests only cover the cases you thought of. Property style tests check rules across many generated inputs. Even a simple loop helps.
[Fact]
public void Validator_never_throws_for_random_input()
{
var random = new Random(12345);
for (var i = 0; i < 10_000; i++)
{
var length = random.Next(0, 400);
var chars = new char[length];
for (var j = 0; j < length; j++)
{
chars[j] = (char)random.Next(32, 127);
}
var exception = Record.Exception(
() => EmailValidator.Validate(new string(chars)));
Assert.Null(exception);
}
}
The fixed seed makes failures reproducible. This test checks the constraint "no exceptions for invalid input", which a handful of examples could easily miss.
Step 4: Review what tests cannot tell you
Passing tests do not prove the code is good. Review these separately:
- Performance: does it allocate on every call?
- Security: could any input cause expensive backtracking if a regular expression is used?
- Readability: will the next person understand it?
- Fit: does it follow your project conventions?
A regular expression is a good example. An overly nested pattern can take a very long time on adversarial input. If a generated solution uses one, set a match timeout and test long inputs.
Step 5: Keep a reusable request template
I find a fixed structure helpful.
Context: what system, framework version, and conventions apply.
Goal: the outcome, in one sentence.
Constraints: what must not change or be used.
Inputs and outputs: types and edge cases.
Acceptance: how I will verify it (tests, benchmarks, review points).
Common failure patterns
| Symptom | Likely cause in the request |
|---|---|
| Correct looking code that does the wrong thing | Goal or edge cases not stated |
| Uses a library you do not have | Constraints not stated |
| Changes unrelated code | Scope not stated |
| Plausible but invented API calls | No reference material supplied |
Invented API calls deserve special attention. Always compile the code and read the official documentation for any method you do not recognise.
What this changes
Using AI well is less about clever phrasing and more about applying engineering discipline: define behaviour, write checks, then evaluate the candidate. The assistant speeds up the typing. You still own the specification and the verification.
Comments
Join the discussionThe email validation example is what made this click for me — a request that looks complete until you list the five open questions, and the model quietly answers all of them for you. The part I'm taking with me is Step 3: my example tests only ever cover the cases I already thought of, so a fixed-seed property test that the validator never throws on random input is a much stronger safety net than a longer list of examples.



