
Stop getting different code every time you ask AI: use a spec pattern
How to write specs so AI generates consistent code: signature, intent, WHEN/THEN rules and tests with RUNE, a free and open specification pattern.
By Pod SRE teamPublished on Updated on 5 min read
The chaos of AI-generated code (and a simple contract to fix it)
Ask three developers to build the same function with AI. Developer A uses Claude. Developer B uses Cursor. Developer C uses ChatGPT.
You get three completely different implementations.
Developer A gets a simple function that returns None on failure. No input validation. Case-sensitive comparison.
Developer B gets a typed function that returns a dict. It checks an “active” flag instead of the expiry date. Different error messages.
Developer C gets a whole class. It pre-indexes the data into a dict. A completely different interface.
Three developers, three AI tools, three functions that don’t fit together. And none of them have tests.
In short: RUNE is a specification pattern that acts as a contract between what you want and what the AI produces. It defines the exact function signature, its intent in a few sentences, its behaviour as WHEN/THEN rules and a minimum of three tests; optionally, the edge cases. With the same spec, Claude, ChatGPT, Cursor or Copilot generate code with the same behaviour, even if variable names or style change. There is nothing to install.
The contract
What if there was a contract between “what I want” and “what AI produces”?
That’s RUNE: a specification pattern we built as part of an open-source project called Runestone. A RUNE spec defines:
- SIGNATURE: the exact function interface.
- INTENT: what the function does (not how), in one to three sentences.
- BEHAVIOR: what happens for every input, written as WHEN/THEN rules.
- TESTS: a minimum of 3 cases that must pass: the happy path, a boundary and an error.
- EDGE_CASES: what happens at the boundaries. It is optional, but every edge case you add should have its own test.
| Section | Required? | What it defines |
|---|---|---|
| SIGNATURE | Yes | Name, typed parameters and return type |
| INTENT | Yes | What the function is for, in one to three sentences |
| BEHAVIOR | Yes | WHEN/THEN rules for every input |
| TESTS | Yes, at least 3 | Cases the code must pass |
| EDGE_CASES | No | Behaviour at the boundaries |
| CONSTRAINTS, DEPENDENCIES, EXAMPLES, COMPLEXITY | No | Constraints, dependencies, examples and expected complexity |
Here’s what it looks like:
RUNE: validate_coupon
SIGNATURE: |
def validate_coupon(code: str, coupons: list[dict], date: str) -> tuple[bool, str]
INTENT: |
Validates a coupon code against a list of coupons and checks it has not expired.
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('save10', [...], '2025-01-15')[0] == True"
- "validate_coupon('', [], '2025-01-15')[0] == False"
Give it to Claude, ChatGPT, Cursor, Copilot…
The generated code has the same behaviour. Internal details (variable names, code style) may vary, but the function produces the same outputs for the same inputs. The tests pass regardless of which tool generated the code.
Not a framework
RUNE is a pattern, not a framework.
There’s nothing to install. No runtime. No dependencies.
You can write specs as YAML .rune files or as Markdown sections inside your existing AGENTS.md. The pattern works with any programming language: Python, TypeScript, Go, Rust, Java, anything.
The lifecycle
The project includes 7 skills: standalone Markdown files you can load into any AI tool to teach it the pattern.
- Writer: creates specs from requirements and implements code from specs.
- Validator: checks whether a spec is complete and well formed.
- Refiner: suggests improvements: missing tests, uncovered edge cases, ambiguous rules.
- Test Generator: converts pseudo-tests into real pytest, Jest or Go test files, ready to run on every commit in your continuous integration pipeline with GitOps and CI/CD.
- Diff: compares spec and implementation to detect drift over time.
- From Code: reverse-engineers specs from existing functions.
- Multi-Lang: generates implementations in several languages from a single spec.
You start with just the Writer and add the others as your workflow matures.
The workflow
For new code:
Requirements → Writer (create spec) → Validator → Refiner → Writer (implement) + Test Generator
For existing codebases:
Existing function → From Code (reverse-engineer) → Validator → Refiner → done
What it guarantees (and what it doesn’t)
Guarantees: the same function signature. The same behaviour for every input. The same error messages. The same edge case handling. Tests that pass across tools.
Doesn’t guarantee: identical code. Variable names, internal structure and code style may differ between AI tools. That’s by design: the contract is about behaviour, not implementation.
Try it
- Go to the repository: github.com/vict00r99/Rune-stone.
- Copy
skills/rune-writer/SKILL.mdinto your AI tool. - Describe the function you need.
- Get a spec, review it and implement it.
- Try the same spec with a different AI tool and compare the results.
It’s MIT licensed. Feedback is welcome: you can write to us through the contact page.
Also published on Medium.
Frequently asked questions
What is a RUNE spec?
A short text, in YAML or Markdown, that describes a function before you ask AI for it: its exact signature, what it does in one to three sentences, its behaviour as WHEN/THEN rules and at least three tests. The AI implements against that contract and the tests check that it holds.
Does it work with any AI tool and any language?
Yes. It is text you paste or load into the tool, so it works with Claude, ChatGPT, Cursor, Copilot or others, and with Python, TypeScript, Go, Rust, Java or any other language.
Does AI always generate the same code from the same spec?
Not the same code, but the same behaviour: the same signature, the same outputs for the same inputs and the same error messages. Variable names, internal structure and style may change; the tests are what confirm the behaviour matches.
Do you need to install or pay for anything to use RUNE?
No. RUNE is a pattern, not a framework: it has no dependencies and no runtime. The repository with the full spec and the skills is MIT licensed.


