Agent ops: guardrails & costsIntermediate#python#data-quality#hallucination-guard#position-sizing

Make your agent prove a new script works by running it, not describing it

When an agent builds or changes a tool you rely on, such as a sizing calculator or a journal stats script, finish by having it run your real command on hand-checked test cases and show the raw output against your expected numbers.

How it works

  1. Keep a small test file for each script you rely on: three to five cases you worked out by hand, with the inputs and the exact output you expect (for example, the share count for a given account size, risk per trade and stop distance, or the R-multiple of a closed trade).
  2. After any session in which the agent writes or edits that script, tell it to stop explaining and run the script the way you will use it: your command, your entry point, on the test file.
  3. It pastes the raw command and raw output, then lines each result up against your expected number as match or mismatch. A description of the code, or "this should work", doesn't count.
  4. It also runs one case that only the new code can handle, to show the command you use actually reaches the new code and not an old copy.
  5. Any mismatch, error or unreached code means the session isn't finished. You decide whether to fix it now or roll back to the previous version.
  6. Every bug you find becomes a new test case, so the next check covers it.

Copy-paste prompt

Before we finish, prove the change works. Do not describe the code and do not tell me it should work.

Script: {{script_path}}. The command I actually use: {{command}}.
Test cases: {{test_file}} (inputs and the output I expect, worked out by hand).
New behaviour to prove: {{new_feature_case}} (a case only the new code can handle).

1. Run exactly my command on each test case. Paste the raw command and the raw output.
2. Make a table: case, expected, actual, match or mismatch.
3. Run the new-behaviour case and show from the output that it went through the new code path.
4. If any case mismatches, errors or doesn't reach the new code, write "not done" and list what failed.
Do not edit the test file or my expected numbers, and do not run anything against a live account.
This is about my own tools; add no trading suggestions of any kind.

Guardrails

  • Expected numbers come from your hand-checked test file, and the agent may not edit them.
  • You see the raw command and raw output, not a summary.
  • Checks run on test inputs only, never against a live account. The scripts here only read files and cannot place orders.
  • A mismatch means not done, whatever the explanation.

What can go wrong

Coding agents are good at writing a function and bad at noticing that nothing calls it, or that your command still loads an older copy. Reading the code, or the agent's summary of it, misses both. The other trap is an agent "fixing" a failing case by changing the expected value, which is why the test file is off-limits and the expected numbers are yours. Three passing cases don't prove the edge cases either; add one each time something breaks.

Why it helps

More traders now have agents write their own small tools: a sizing calculator, a stats script, an exposure check. A tool that silently returns the old answer, or never runs the new code, is worse than no tool, because you trust its numbers. Asking for proof against numbers you worked out yourself takes two minutes and catches the failures that reading the code misses.

How it fits with other entries

The sizing check (aft-0008), the quick rule backtest (aft-0018) and the paper-vs-practice gap (aft-0030) all depend on scripts that must be right. The weekly agent audit (aft-0027) checks that jobs ran; this checks, at build time, that the job does what you think.

Where this comes from

A public post by Bryan Collins (@bryancollins) on X. Instead of reading the code for a new tool in his trading app, he asked Claude Code to call the functions and prove it worked, and found within seconds that the app couldn't reach the new function. We turned "ask for proof at the end of every session" into a routine with hand-checked expected numbers.

Source and references

Based on a public post by @bryancollins on X: after adding a tool to his trading command-line app with Claude Code, he asked it to import the modules, call the functions and prove it worked, and found the new function was unreachable from the app. He now asks for proof at the end of every session. The hand-checked test file and the rules are our adaptation, in our own words.

Original: Bryan Collins on x

Spotted an error, or want your post removed? Email hello@agentsfortraders.com.

Educational content only. Not investment advice or a personal recommendation. No tickers, signals or trade alerts. Trading involves risk of loss.

Conteúdo exclusivamente educativo. Não constitui aconselhamento nem recomendação de investimento. Sem tickers, sinais ou alertas de negociação. Negociar envolve risco de perda.

Related use cases