Skip to main content

AI Coding Tip 044 - Make Your Spec Executable

Markdown is a great spec, so the AI always follows it, right?

Updated 5 min readMarkdown
Part of seriesAI Coding Tips
AI Coding Tip 044 - Make Your Spec Executable

TL;DR: Turn each requirement into an executable acceptance test, and let a red test tell the AI it missed the spec.

Common Mistake โŒ

You write a clean spec in Markdown and hand it to the AI.

The AI writes the code.

Then you run the system by hand and compare it with the spec, line by line.

The AI skipped a line this morning.

You miss the same line on Friday afternoon.

You automated everything except the checking.

Problems Addressed ๐Ÿ˜”

  • The AI skips or misreads a line of the spec, and you find out in production.

  • You verify by hand, so every change costs another manual round.

  • The Markdown stops being true, and you don't notice.

  • You read the diff and guess the requirement behind it.

  • You stop trusting the AI and recheck everything.

How to Do It ๐Ÿ› ๏ธ

  1. Pick one requirement from your Markdown spec.

  2. Write it as an acceptance test that fails today, before the AI writes any code.

  3. Name the test after the behavior in the spec, so the failure message reads like the requirement.

  4. Show the AI the failing test, and ask it to make it pass without touching the test.

  5. Run the suite inside your harness and let the AI read every red test.

  6. End every task with a criteria check that fails while a spec test is red.

  7. Review the tests yourself, line by line, since the AI can misread the spec in a test as easily as in the code.

  8. Keep the Markdown, and update it together with the tests when a requirement changes.

  9. Add a regression test every time production teaches you a case the spec forgot.

Benefits ๐ŸŽฏ

  1. Verify without you: The test tells you if the AI followed the spec, and you stop clicking through the system.

  2. Catch misreadings early: A red test shows the gap before the release.

  3. Let the AI retry alone: It reads the failure, fixes the code, and runs the test again.

  4. Keep the spec alive: A spec that can fail can't quietly go stale, and specs aren't carved into stone.

  5. Review the requirement: You check the test against the requirement before you open the diff.

Context ๐Ÿง 

Spec-driven development has a gap.

A Markdown spec only asks for something, and nothing checks the answer.

The AI can skip a line or misread it, like any developer whose story the testers send back.

An executable spec is an acceptance test that stays red until the system does what the spec says.

It's test-driven development (TDD): red test first, code second.

TDD isn't a testing technique, and neither is this.

Human review is the most expensive resource you have today.

You can't speed it up, so you automate the criterion it applies.

A test is that criterion, and it runs on every change.

Prompt Reference ๐Ÿ“

Bad Prompt ๐Ÿšซ

Read SPEC.md and implement the checkout feature.
Make sure it follows the spec.
Test it when you finish it.

Good prompt ๐Ÿ‘‰

Read SPEC.md, requirement 4: free shipping over 100 dollars.
Write an acceptance test for it first.
Name the test after the requirement.
Run it and show me the red failure.
Don't write any production code yet.
Wait for my review of the test.
After I approve it, implement the code.
Don't edit the test to make it pass.
Use an adversary agent to run the full suite and fix every red test.
Stop when all the spec tests are green.
Then list each requirement and the test that proves it.

Considerations โš ๏ธ

A test only covers what somebody thought to write.

The expensive failures live in the cases nobody listed, like a retry or a half-finished payment.

If the AI writes the tests from the Markdown, its misreading lands in the test too, and the test passes.

The AI can also cheat when it weakens the test until it goes green.

I'd rather read the tests myself, or ask a second model to write them.

The Markdown stays.

It still says why.

Not every line of a spec deserves an acceptance test.

You should start with the requirements that cost money when they break.

Type ๐Ÿ“

[X] Semi-Automatic

Limitations โš ๏ธ

Writing good acceptance tests takes work, and the first ones are slow.

A flaky test teaches you to ignore red.

Some requirements, like look and feel, are hard to automate.

Tags ๐Ÿท๏ธ

  • Planning

Level ๐Ÿ”‹

[X] Intermediate

Related Tips ๐Ÿ”—

https://maximilianocontieri.com/ai-coding-tip-008-use-spec-driven-development-with-ai

https://maximilianocontieri.com/ai-coding-tip-033-protect-yourself-against-ai-cheating

https://maximilianocontieri.com/ai-coding-tip-024-force-a-criteria-check-before-the-task-ends

https://maximilianocontieri.com/ai-coding-tip-022-give-ai-a-harness-to-work-with

https://maximilianocontieri.com/ai-coding-tip-037-stop-patching-blind

Conclusion ๐Ÿ

Your spec finally has a way to say no.

Which line of yours did the AI skip last?

More Information โ„น๏ธ

Acceptance testing, Wikipedia

Behavior-driven development, Wikipedia

Also Known As ๐ŸŽญ

  • Spec-As-Test

  • Executable-Specification

  • Acceptance-Test-First

  • Test-Judged-Specs

Disclaimer ๐Ÿ“ข

The views expressed here are my own.

I am a human who writes as best as possible for other humans.

I use AI proofreading tools to improve some texts.

Most AI detectors will flag this article as AI-generated. That's expected. It's a technical article. It has a rigid format and clear steps to follow.

That's exactly the pattern those tools are trained to catch. I've apparently been "writing like an AI" for decades, long before AI existed. This is a technical article, not a novel.

I welcome constructive criticism and dialogue.

I shape these insights through 30 years in the software industry, 25 years of teaching, and writing over 500 articles and a book.

Credits ๐Ÿ™

Photo by Markus Spiske on Unsplash


This article is part of the AI Coding Tip series.

https://maximilianocontieri.com/ai-coding-tips

2 views

About the author

  • Iโ€™m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.

Nnetproxy1h ago

The part about the AI misreading the spec inside the test itself is the one I'd underline โ€” having a second model write the tests, or writing them yourself, is what keeps the loop honest. I keep my specs in Markdown in VS Code and use ViewAny to preview them next to the tests, so the spec stays the readable source of truth while the failing test is what actually enforces it.