DEV Community

Cover image for Stop Getting Different Code Every Time You Ask AI — Use a Spec Pattern
Victor Piles
Victor Piles

Posted on

Stop Getting Different Code Every Time You Ask AI — Use a Spec Pattern

Every time I ask AI to "write a function to validate coupons," I get a different result. Different function names, different return types, different edge cases handled. Three developers, three AI tools, three incompatible implementations.

So I built Runestone — an open-source specification pattern called RUNE that acts as a contract between what you want and what AI generates.

The idea

Instead of describing what you want in plain English and hoping for the best, you write a short spec:

RUNE: validate_coupon

SIGNATURE: |
  def validate_coupon(code: str, coupons: list[dict], date: str) -> tuple[bool, str]

BEHAVIOR:
  - WHEN code is empty THEN return (False, "Coupon code cannot be empty")
  - WHEN code not found (case-insensitive) THEN return (False, "Not found")
  - WHEN coupon has expired THEN return (False, "Expired")
  - OTHERWISE return (True, matching_coupon)

TESTS:
  - "validate_coupon('SAVE10', [...], '2025-01-15')[0] == True"
  - "validate_coupon('', [], '2025-01-15')[0] == False"
  - "validate_coupon('OLD', [...], '2025-01-15')[0] == False"
Enter fullscreen mode Exit fullscreen mode

Give this to any AI tool — Claude, ChatGPT, Cursor, Copilot... and the generated code has the same behavior. Same signature. Same edge cases. Same error messages. Same tests.

What it includes

  • A pattern (not a framework) that works as YAML files or Markdown sections
  • 7 skills you can load into any AI tool:
    • Writer — create specs and implement code
    • Validator — check spec completeness
    • Refiner — suggest improvements
    • Test Generator — generate real test files from specs
    • Diff — detect drift between spec and code
    • From Code — reverse-engineer specs from existing functions
    • Multi-Lang — same spec, multiple languages
  • Works with any programming language
  • No installation, no runtime, no dependencies

What it doesn't do

It doesn't generate identical code character-by-character. Variable names and internal style may vary between AI tools. What stays consistent is the behavior: same inputs, same outputs, same edge case handling, same error messages. The tests from the spec pass regardless of which AI generated the code.

Try it

  1. Copy skills/rune-writer.md into your AI tool
  2. Describe a function you need
  3. Get a RUNE spec
  4. Implement from the spec
  5. Do it again with a different AI tool — compare the results

GitHub: https://github.com/vict00r99/Rune-stone

Would love feedback. What would make this useful for your workflow?

Top comments (0)