Locked Paths: A Prompt Is a Request. A Test Is a Rule.
Cross-post of Insights #19. Canonical: https://sheikhwasim.com/insights/locked-paths-prompt-is-a-request-test-is-a-rule/
Every team running coding agents has a line in a prompt that says something like "do not modify the payment retry logic." It feels like a guardrail. It isn't one.
A prompt is a request. The agent will honor it most of the time, and when it doesn't, it will usually have a reasonable-sounding explanation. Production doesn't care about the explanation.
The fix is a habit I call Locked Paths: any code an agent must never change on its own gets protected by something the agent can't talk its way past - a test that pins the behavior, and a merge rule that needs a human.
Quick use case
Situation. A fintech team uses a coding agent to clear its backlog of small tickets: flaky tests, log cleanup, dependency bumps. The agent's instructions say, in bold, "Never change payment retry behavior." Reviews are light because the tickets are small and the agent's PRs have been clean for weeks.
What broke. A ticket asks the agent to fix a flaky integration test in the payments service. The test sometimes times out. The agent traces the timeout to the retry loop, sees three retries with exponential backoff, and "simplifies" it to one retry so the test runs faster.
The PR description says "fixed flaky timeout in payments test; minor cleanup in retry helper." Tests pass. A reviewer skims it and approves. Three days later a card processor has a short outage. Payments that used to recover on the second or third retry now fail on the first. Support gets a wave of "my payment didn't go through" tickets before anyone connects it to a cleanup PR.
The agent didn't ignore its instructions out of malice. It decided the change was a test fix, not a retry change. The instruction lived in the prompt. Nothing in the repo knew about it.
The fix (Locked Paths)
- Name the paths. The team listed the code nobody - human or agent - should change casually: retry policy, idempotency keys, refund math, auth checks.
- Pin the behavior with tests. A small test now asserts the retry count, the backoff schedule, and that retries reuse the same idempotency key. If anyone changes the behavior, that test fails, whatever the PR description says.
- Require a human owner. A
CODEOWNERSentry puts the retry module under the payments lead. Branch protection means no merge without that person's approval. - Make the agent stop, not decide. If an agent's change touches a locked path, it stops and opens the PR as "needs owner review" with a plain note on what it changed and why.
Same agent, same prompts. The next time it tried to "clean up" a locked file, the pinned test failed in CI, the PR waited for the owner, and the owner said no in one comment.
Why prompts aren't guardrails
A prompt instruction competes with everything else in the context: the ticket, the code, the error log, the agent's own plan. When the ticket says "make this test pass" and the shortest route runs through a protected file, the agent has to weigh one sentence against the whole task. Most of the time it gets that right. You need it to get it right every time.
Prompts also don't travel. A rule in one agent's system prompt doesn't protect you from a different agent, a new model version, or a tired human on a Friday. A rule in the repo applies to all of them.
And prompts fail quietly. When an agent breaks a prompt rule, nothing turns red. When it breaks a pinned test, CI does.
The Locked Paths framework (four layers)
- Inventory - know what's locked
Keep a short list (a LOCKED_PATHS.md or a section in your agent config) of files and behaviors that carry money, security, compliance, or customer trust. Ten entries beats a hundred. If everything is locked, nothing is.
- Pin - make the behavior testable
For each locked path, write one or two tests that assert the behavior itself, not the implementation: "three retries, same idempotency key," "refund never exceeds the original charge," "admin routes reject non-admin tokens." These are the tests that should fail loudly when someone "simplifies" things.
- Own - put a human on the merge
Use CODEOWNERS and branch protection so changes to locked paths need a named human's approval. The agent can open the PR. It can't merge it, and neither can a reviewer who doesn't own that code.
- Stop - teach the agent to hand off
Give the agent a clear rule it can actually follow: if your diff touches a locked path, stop, label the PR, and explain the change in plain language. This one belongs in the prompt, because now it's backed by layers 1-3. The prompt tells the agent what to do; the repo makes sure it happens.
Try this on Monday
Open your agent's instructions and find every "never," "don't," and "do not." For each one, ask a single question: if the agent ignored this line, what would fail? If the answer is "nothing until a customer notices," that line is a request.
Pick the one with the biggest blast radius and turn it into a rule this week: one pinned test, one CODEOWNERS entry, one branch protection setting. It's usually less than an hour of work.
Closing
Agents are getting better at following instructions, and they'll keep getting better. That's not the point. The point is that the code paths you care about most shouldn't depend on anyone - agent or human - remembering a sentence. Write the rule where the repo can enforce it, and let the prompt do what prompts are good at: explaining the rule.
If you're putting coding agents near payments, auth, or anything else you can't easily undo, I'd like to hear how you lock those paths down. Connect with me on LinkedIn - I share what holds up in production there every week.
I'm Wasim Sheikh, AI Architect. I build systems teams trust and organizations depend on: not demos, not proofs of concept, production. Follow for practical AI architecture that ships. Connect on LinkedIn: Wasim Sheikh ยท Site: sheikhwasim.com ยท Notes: Wasim Sheikh on Substack (practicalainotes.substack.com) ยท X: @anciwasim
Comments
No comments yet. Start the discussion.