Archive / Put your AI trading rules in code, not in the prompt

Put your AI trading rules in code, not in the prompt

An AI agent can talk its way around "be careful". This prompt turns your trading rules into checks that run in code before any order can go out.

Nothing here is financial advice or a recommendation to buy, sell or trade anything. Do your own research.

For: Solo founders, New to AI

Topics: Investment, Agent management

Why I'm sharing it

Builders who share their AI trading experiments online keep telling the same two stories. In one, two copies of an agent ran at the same time and both placed the same trade. In the other, an options bot couldn't load its chart data and made up a signal instead of stopping.

Both agents had prompts that told them to be careful. It didn't help. A prompt is a request. A rule in code is a wall.

So before I'd let any agent near an order, I want a short list of checks that run outside the agent, which the agent can't edit or argue with.

What makes it work

It separates proposing from sending. The agent can suggest a trade. Only the checks can pass it on.

It fails closed. Missing or stale data means no trade, never a guess.

It stops on surprises. If the broker shows something your own log doesn't, everything halts until a person looks.

It makes every check testable. Each rule comes with a test that proves it fires.

It keeps a person in the loop. Real orders wait for a human yes, and a yes that sits too long expires.

The prompt

Prompt

You're helping me design the risk checks for an AI trading agent. The agent can only propose orders. A separate piece of code must check every proposal before anything reaches a broker, and the agent must not be able to change those checks. My rules: [paste your rules, for example paper trading only, a watchlist, a maximum loss per trade, a stop on a total drop, which instruments are allowed]. Write a numbered list of checks in plain English. Include at least these: 1. Only one run at a time; a second run must exit, not trade. 2. No order without a written reason and a stop price. 3. Any ticker not on my watchlist is refused at the order. 4. If the broker's positions or orders don't match my log, halt and alert me. 5. Missing, stale or conflicting market data means no trade. 6. Every order carries a unique key so a retry can never send it twice. 7. One off switch stops everything and cancels open orders. For each check, say what it protects against, where it runs, and one test I can run to prove it works. Then list any of my rules that can't be checked in code and say what I'd have to do by hand instead.

How to use it

Write your rules first, in your own words, even if they're rough. The prompt is only as strict as what you give it.

Build and test the checks on a paper account long before real money. A check you've never seen fire is a check you don't have.

Keep the keys to any real account away from the agent. The checks should be the only door.

This is about building safer software, not about what to trade. It isn't financial advice, and nothing here is a recommendation to buy, sell or trade anything.

Based on stories other builders shared online about AI trading agents that double-traded or made up signals. The checks here are my own write-up.

Use it for: Writing the risk checks for any AI agent that could place an order, before it ever touches a real account.

Back to the archive