Apply to my task
arXiv:2609.23270 ★ 94 Sep 20, 2026

Specification Frame: a ready-made instruction block that cures money, dates, and passwords in AI-generated code

Key result

The paradox: instruction files like AGENTS.md don't actually make code safer. The largest controlled study of such files (cited by the paper) found they did not generally improve results, could even reduce them, and added more than 20% to cost. Specification Frame solves this differently: it lets you get code from a model without the classic bugs — money handled as float, dates missing timezones, payments charged twice — using one fixed 267-word block. The block doesn't describe HOW to write the code, but WHAT must be true in the result. Tested on 5 models from 5 different companies — errors dropped in all five (148 to 23 findings overall), and no model got worse.

01

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.

Research digest

Key result

The paradox: instruction files like AGENTS.md don't actually make code safer. The largest controlled study of such files (cited by the paper) found they did not generally improve results, could even reduce them, and added more than 20% to cost. Specification Frame solves this differently: it lets you get code from a model without the classic bugs — money handled as float, dates missing timezones, payments charged twice — using one fixed 267-word block. The block doesn't describe HOW to write the code, but WHAT must be true in the result. Tested on 5 models from 5 different companies — errors dropped in all five (148 to 23 findings overall), and no model got worse.

Principle

An instruction explains how to work — style, file structure, formatting. A specification explains what the result should be — concrete, checkable rules. As the paper puts it, generic instruction does little, stated constraints do a lot. 'Write secure code' is a style preference — you can't verify it. 'Never compare money using float equality' is a rule you can check line by line.

Why it works

Our explanation: the model was trained on millions of code examples where money is stored as float and time is handled as timezone-naive datetime. That's the shortest path for tutorial-style demo code, so the model just repeats the familiar pattern. The model isn't dumb — it simply doesn't know that this particular task requires production-grade rigor rather than tutorial-grade code. The effect is strongest exactly where the model is weakest by default — the block acts as a safety net right where it's needed most.

When to apply

Backend development → generating code for payments, dates and times, retried requests (webhooks), passwords and file access — as a baseline, not a replacement for review. Tested only on Python backend tasks. NOT suitable for creative code, frontend, or UI logic — the effect hasn't been tested there at all.

Mini recipe

1. Set the role: a senior backend engineer at a fintech company whose code gets reviewed before every release 2. Add rules: money only via Decimal, time only with timezone info, SQL only through parameterized queries, secrets only from environment variables 3. Describe the task right after: in a single message, no back-and-forth or clarifications after the block 4. Trim the block: if the task doesn't involve money or dates, remove those points to save tokens (our suggestion; the paper tested only the full block) 5. Add your own rules: put legal or API-specific requirements in a separate "Constraints" section — the block doesn't replace that

Examples

[BAD]: `Write a Stripe payment webhook handler for a Slack bot that logs the payment to the database` [GOOD]: `Role: you are a senior backend engineer at a fintech company. Rules: money only via Decimal, a repeated call to the handler must not double-charge the payment (check the idempotency key), SQL only through parameterized queries. Task: write a Stripe webhook handler with fields payment_id, amount, currency, status, save the payment to the orders table, return 200 OK`

In plain words

Models write janky code not because they're dumb, but — our guess, not the paper's finding — because the internet is flooded with bargain-bin tutorials. The model learned from millions of examples pulled from sandbox projects where money is calculated with float and time gets stored without any timezone awareness. For the model, that's the default norm. If you don't rein it in from the start, it'll spit out code fit for a college lab assignment — and you'll end up with a security hole out of nowhere.

It's like hiring a handyman and saying: "Just wire up the kitchen." He'll twist the wires together and slap on some blue electrical tape, because technically the current flows, and nobody said a word about fire codes. The model behaves exactly the same way: it takes the shortest path until you explicitly force it to follow the code.

The fix is a method called the Specification Frame. It's a fixed block of just 267 words that gets bolted on before the task. It doesn't teach the model style or file structure — it lays down ironclad rules of the game: it bans float for money, requires idempotency on repeated requests, and forces proper hashing for access control.

The author tested the approach on five different models, and the trick worked across the board. It was tested on Python backend tasks — money, dates, retries, and logins — not on every kind of code. Within that scope, slotting it in cut the checkers' findings by 84% (148 down to 23).

Bottom line: stop begging the model to write code that's "robust and clean" — to the model, that's just empty chatter. Bake a strict specification in before generation, and stop manually hunting down lost pennies and duplicate charges. One block of text saves your production environment from disaster.

AI lab assistant

Apply this study to your task

Describe what you're working on. AI takes the method and the measured results from this paper and adapts them to your case, or writes a ready prompt built on them.

Based on Specification Frame: a ready-made instruction block that cures money, dates, and passwords in AI-generated code arXiv:2609.23270

Sign in to apply this study New accounts get 50 free credits.