TL;DR
Specification Frame is a fixed 267-word block of text you paste in front of a code-generation task. It doesn't teach the model how to write (style, file structure) — it tells the model directly what must be true about the result: how to handle money, how to store passwords, how to handle repeated requests. In the study it worked like a pre-installed "firmware" — the same block, unchanged, for all 50 tasks.
The core pain point: models write code that looks correct but contains the same classic bugs over and over — money handled through floats (rounding drifts), dates without a timezone (a recipient in another city gets an email at 2 a.m. instead of 9 a.m.), a retried payment request can charge someone's card twice, passwords get stored the wrong way. And instruction files ("AGENTS.md", "rules for Cursor") don't reliably fix this — the paper cites the largest controlled study of such files (on AGENTS.md), which found they did not generally improve task success, could even reduce it, and added more than 20% to cost.
The difference is that an instruction explains "how to work," while a specification explains "what the outcome should look like." The author tested a short block with concrete constraints (money — only via Decimal, time — only with a timezone, payments — only with duplicate-request checks) on 5 different models from 5 different companies, and the block reduced the number of bugs in all five without exception — 148 checker findings fell to 23 overall (84% fewer). No model and no task area got worse, though 5 of the 100 task pairs that differed had more findings with the block.
Method Blueprint
STEP 1: Paste the Specification Frame (role + context + rules) → a fixed block, unchanged regardless of the task
STEP 2: Right after it, describe your task as usual → one message, one request
Both steps go in a single prompt, with no back-and-forth or clarifying questions.
Example in Action
Our illustration, not a task from the paper. The prompt below is our shortened adaptation of the frame.
Task: A small business owner is building a Discord bot to accept payments through Stripe and asks Claude to write a webhook handler — code that receives a "payment succeeded" notification and writes it to the database.
Prompt:
Role: you are a senior backend engineer working in the codebase of a financial service,
where code is reviewed against security requirements before every release.
Context: Python 3.12, standard library. The following rules apply:
- Monetary amounts only via Decimal or integer cents, never via float.
- All dates and times must carry an explicit UTC timezone; no "naive" datetimes allowed.
- SQL queries only via parameterized placeholders.
- Keys and tokens only from environment variables, never hardcoded in the code.
- Secrets and personal data must never end up in logs.
Task: implement exactly what is described below, and nothing more.
Constraints:
1. Money arithmetic — Decimal or integer cents only. Round only at the final
step. Never compare money using float equality.
2. Any handler that can be called more than once (a payment webhook) must require
and validate an idempotency key before applying its effect — meaning a duplicate
notification must not credit the payment a second time.
3. Validate input at the boundary; on error, reject the request — don't let anything through "just in case."
4. If the wording is ambiguous, pick the strictest interpretation.
Task: write a Stripe webhook handler that receives JSON with fields
payment_id, amount, currency, status, records a successful payment in the orders
table, and returns 200 OK.
What to expect: The model produces one piece of Python code. Compared to a bare request without the block, you can expect that the amount is handled through Decimal instead of float, the handler requires an idempotency key (so a repeated Stripe webhook doesn't credit the payment twice), and there are no raw SQL strings with variables spliced in. (In the paper, money findings fell from 66 to 8 and idempotency findings from 32 to 2 across the five models.)
Why It Works
Our explanation (the paper does not test this): by default, a model writes code the way it most often saw in training data — and that data is full of tutorial examples using float for money and naive datetime, because that's the shortest path for demo code. The model isn't "dumb" — it simply doesn't know that this particular task needs production-grade rigor, not tutorial-grade shortcuts.
The paper points to a pattern across studies: "generic instruction does little, stated constraints do a lot." Models are much better at following explicitly stated constraints when they're concrete rather than abstract. "Write secure code" is a style request — vague and fuzzy. "Never compare money using float equality" is a specification — a concrete rule you can check line by line.
The method works because it shifts the focus from instructions about style to a description of the outcome. The effect was strongest in the models that made more mistakes without the block (an observed pattern across the five models) — meaning the block acts as a safety net right where it's needed most.
Control levers (our suggestions; the paper used one fixed block and did not test trimmed or modified versions): - You can trim the rules block if the task doesn't touch money or dates (keep only the relevant items) — saves tokens. - You can add your own domain-specific rules to the "Constraints" section (e.g., rules for a particular regulation) — the block doesn't replace task-specific detail, it just sets a baseline floor. - The role can be swapped for your own context ("senior backend engineer" → "embedded systems engineer") — sharpens execution for the domain you need.
Prompt Template
Role: you are a senior backend engineer working in the codebase of a financial
and healthcare service, where code is reviewed against security requirements
(PCI DSS, HIPAA) before every merge.
Context: stack — {specify language and version}. The following rules apply:
- Monetary amounts only via Decimal or integer cents, never via float.
- All dates and times must carry an explicit timezone (UTC); no "naive" datetimes without a zone allowed.
- SQL queries only via parameterized placeholders, never via string concatenation.
- Passwords and access keys only from environment variables, never hardcoded in code or logged.
- Secrets, personal data, and card numbers must never end up in logs.
Task: implement exactly what is described below, and nothing more.
Constraints:
1. Money arithmetic — Decimal or integer cents only. Round only at the
final step, "round half up." Never compare money using float equality.
2. Any handler that can be called more than once (webhooks, payments) must be
idempotent: it must require and validate an idempotency key before applying its effect.
3. Store passwords only via slow, salted hashes (scrypt, pbkdf2 with a high iteration
count). Never in plain text or via a fast unsalted hash.
4. Validate redirect target URLs against an allow-list.
5. Validate file paths coming from user input — they must stay within the
allowed base directory.
6. Validate input at the boundary; on error, reject the request — don't let anything through "just in case."
7. If the wording is ambiguous, pick the strictest interpretation — don't invent extra requirements.
Task: {your task description}
Fill in the programming language, platform, and your actual task inside the curly braces. This template is our reconstruction from the paper's description of the frame (Role, Context, Task, Constraints; the role names PCI DSS and HIPAA; seven constraints). The exact 267-word text that was tested is in the paper's dataset; our wording itself was not tested.
🚀 Quick start — paste this into the chat:
Here's a Specification Frame template for code generation. Adapt it to my task: {your task}.
Ask me questions to fill in the fields.
[paste the template above]
The LLM will ask about the programming language and task specifics — because that determines which constraints in the block are relevant and which can be dropped. It will take the role-and-constraints structure and adapt it to your task.
Limitations
⚠️ Doesn't replace a task description: the block sets a security baseline, but it doesn't know the business logic of your specific task. Task-specific requirements (tax rules, API formats) still need to be spelled out separately.
⚠️ Works for a specific class of code: the measured effect covers money, time, retried requests, and access control, in Python only, in single-turn generation without tools. Applicability to other languages, agentic coding, creative code, frontend, or UI logic hasn't been tested.
⚠️ Fewer flagged bugs is not the same as working code: the study counted findings from its nine checkers and Bandit; it did not test whether the code works correctly, and the checkers can miss bugs.
How It Was Tested
Before running a single test, the researcher locked in the hypotheses, failure criteria, and a "one attempt only" rule: once a model produced a result, it could not be regenerated, even if it flopped. This removes the biggest temptation — quietly cherry-picking runs to fit the desired outcome.
Next, the researcher wrote 50 tasks in four areas (money, idempotency, date and time, authentication), realistic for finance, healthcare, and insurance backends (partial refund calculations, payment webhooks, login checks, scheduling a meeting across timezones) and ran each one through 5 top models from 5 different companies (Claude Sonnet 5, GPT-5.6, Gemini 3.1 Pro, DeepSeek V4 Pro, Qwen3.8-27B), twice — once without the block, once with it. That's 500 generated snippets of code total.
The code was scored two independent ways: nine automated checks against the code's syntax tree (catching specific bugs — floats for money, naive dates) and a separate security scanner, Bandit, which has no idea this block even exists — a safeguard against overfitting to the test. Both methods showed the same thing: with the block, bugs dropped dramatically (148 to 23 checker findings; 53 to 11 Bandit issues), and the effect was strongest for the models that made the most mistakes without it — though the models still differed after the block (from 2 to 9 findings each).
Want this for your own case? Apply this study to your task: AI adapts its method to what you are working on and writes the prompt.