TL;DR
When you ask Claude to write code without mentioning security at all, the model does exactly what you asked — nothing more. It hashes passwords and adds encryption where that's just part of the "normal" way to write that kind of code, but it skips everything that requires extra, separately-invoked steps: storage access configuration, logging, data retention policy, MFA.
The spread is brutal: in some tasks the model met up to 88% of security requirements on its own; in others, only 47%. Worse — in three of the eight neutral runs of the first two models (all in the personal-data upload task), the code contained real holes: an exposed debugger with remote code execution capability, an unauthenticated download, and an endpoint that returned every stored name and email. A fourth defect turned up in a later Opus 5 run. And the first review checklist didn't catch these holes at all.
The fix turned out to be almost laughably simple: add one sentence to the prompt saying the data is sensitive and the code must comply with the SOC 2 standard — the sentence named no individual measure. This bumped compliance in every task to 86–100% and eliminated every vulnerability found. Some controls were still missed (MFA hooks, cookie flags, account lifecycle). Only SOC 2 was tested; other standards (GDPR, CCPA, PCI DSS) may work similarly, but that is our guess. The authors' reading: the added protections were within the model's reach before; it simply didn't consider them part of the task.
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.
Method Blueprint
STEP 1 (no method): Prompt about the task with no mention of security
→ model writes working code with a partial set of protections
(only the ones "baked into" the standard way of writing this kind of code)
STEP 2 (the method): Add one sentence to the same prompt:
"this data is sensitive, the artifact must comply with [standard]"
→ model fills in most of the technical measures on its own (encryption,
access control, logging, retention) — but not MFA hooks, cookie flags
or account lifecycle
Everything happens in a single prompt — no separate follow-up requests needed.
Example in Action
Our illustration. The paper's sentence named only SOC 2 and the data's sensitivity; the prompt below names GDPR/CCPA and lists specific measures, which the paper did not test.
Task: The owner of a small online service asks Claude to write backend code for a lead-capture form that collects customers' email and phone number to store in a database for email marketing.
Prompt:
Write Python (Flask) code for an endpoint that accepts an email
and phone number from a website form and saves them to a PostgreSQL database.
This is customer personal data, so processing must comply
with GDPR/CCPA requirements and include encryption at rest, restricted
access to the database, access logging, and a data retention policy.
Expected result (our illustration): The model writes code that encrypts fields on write to the DB, avoids hardcoding database passwords (using environment variables instead), logs access to the data, and includes a sample policy for purging stale records. Without that second paragraph, it would likely skip some of these protections — in the paper's personal-data upload task, neutral code met only 50–75% of the checklist, and three of the eight neutral runs of the first two models had real holes.
Why This Works
The authors' reading: by default, the model solves literally the task it was given. If the task is "save this email to the database," it does exactly that, with the minimal set of actions required. Extra steps — encryption, logs, retention — aren't part of the task definition, so the model doesn't add them, even if it technically knows how.
At the same time, the model evidently knows many measures that correspond to SOC 2 — once the standard was named, it added them without being told which ones. The problem isn't lack of knowledge; it's that without an explicit trigger, the model doesn't treat that knowledge as part of the request.
By naming the standard, you change the actual framing of the task — "write the code" becomes "write code that complies with standard X," and the model pulls out the entire mental checklist of technical measures it associates with that standard.
Levers you can pull (our suggestions; the paper tested only one SOC 2 sentence): - Swap "SOC 2" for GDPR, PCI DSS, CCPA, HIPAA — the model will likely apply the set of measures it associates with the named standard. - Specify the data type ("personal data," "payment information," "health data") — may strengthen the effect. - For narrow, specific measures (MFA, cookie flags, account lifecycle policies), the generic phrase didn't cut it in the paper — name those separately and explicitly.
Prompt Template
Our template, not the paper's wording — it adds named measures and other standards that were not tested.
Write {code/function/service} for {task}.
This data is {data type: personal data / payment information /
health data}, and processing must comply with {standard:
SOC 2 / GDPR / CCPA / PCI DSS} and include encryption at rest,
restricted access, access logging, and a data retention policy.
Fill in {task} with a concrete description of what the code should do, and {standard} with the law or standard actually relevant to your situation (for US-based projects, that's often CCPA, HIPAA, or PCI DSS depending on the data type).
Limitations
⚠️ The directive doesn't cover everything: MFA,
Secure/HttpOnlycookie flags, account lifecycle rules — the generic standard-mention phrase didn't activate these. Naming them separately is our suggestion.
⚠️ 100% on the checklist is not a guarantee of passing a real audit. Compliance was measured against the researchers' own technical interpretation, not an official SOC 2 checklist — the standard dictates goals, not specific technical implementations.
⚠️ Model choice mattered least — within three Claude models. Claude Fable 5 and Opus 4.8 finished within one checklist item of each other in every comparison; the newer Opus 5 improved the two weakest cases by less than the sentence did. No other vendors were tested, and each cell was a single generation with one wording of the sentence.
⚠️ Eyeballing the code or running a pattern-based automated scanner isn't reliable. In the study the pattern-matching scorer disagreed with meaning-based grading on 27 of 216 judgments and passed a real defect — you need a review based on actual meaning (e.g., having another model or a human read the whole thing).
How This Was Studied
A team from Vanta took three top-tier Claude models and asked them to write code for four typical tasks: uploading files to S3, an authentication service, database infrastructure in Terraform, and a file-upload handler for personal data. Each model ran each task twice — once with a neutral prompt (zero mention of security) and once with the same prompt plus one sentence about SOC 2 — one generation each, 24 outputs in all. Results were checked against a pre-written checklist of 12–15 items, each the authors' mapping of a SOC 2 criterion to a technical measure, and every failure was manually verified rather than trusted to automation.
A fun detail: the first version of the "dangerous actions" checklist found zero problems across the 16 generations of the first two models — and that wasn't a flaw in the code, it was a flaw in the checklist. When the researchers expanded the list of vulnerabilities to check for, real defects surfaced: an exposed debugger with remote code execution, an unauthorized endpoint leaking other users' data (the authors note the expansion was made after reading the code). This supports a practical takeaway: automated pattern-matching scanners can get it wrong in both directions — all ten flags of the first checklist were false alarms, while real holes went unflagged — so blindly trusting them to review AI-generated code is a bad idea.
Resources
Can AI Write Compliant Code, and to What Extent? — Iccha Sethi, Herman Errico (Vanta).