Agent ops: guardrails & costsIntermediate#data-quality#hallucination-guard#python#cost-control

Turn your agents' past mistakes into a test set to rerun when anything changes

Each time an agent in your routine gets something wrong, save the input and the right answer as a test case. Before you switch models, edit a prompt or add a tool, rerun the set and compare it with the last baseline.

How it works

  1. Make a test folder for one agent job you rely on, such as tagging journal trades, filing daily notes or checking a plan against your checklist. Each case is one file: the exact input, the answer you checked by hand, and a one-line note on what went wrong the first time.
  2. Whenever you catch that agent making a mistake, fix the job, then add the case to the folder before moving on. Add two or three cases where it did the job well, so you also notice when a change breaks something that worked.
  3. Freeze the inputs. Use saved copies of files and tool outputs, not live data, so a rerun tests the agent and not today's market.
  4. When anything changes (a new model, a provider switch, an edited prompt or rules file, a new tool or connector), a small script runs every case through the job and compares each output with the expected answer, using exact checks wherever possible: tags, counts, dates and numbers.
  5. The script reports passed, failed and changed cases against the last baseline, plus run time and cost, and saves the report with the date and a note of what changed.
  6. You decide whether the change stays. A case that used to pass and now fails blocks the switch until you've looked at it.

Copy-paste prompt

You run my private test set for one of my agent jobs. You do not give trading advice and you never comment on markets or securities.
Inputs: the test folder {{tests_dir}} (each case has input, expected_output and note), the job's current prompt and settings {{job_config}}, and the previous report {{baseline_report}}.
1. Run every case through the job exactly as configured, using only the saved inputs. Do not fetch live data.
2. Compare each output with expected_output. Use exact comparison for tags, counts, dates and numbers; for free text, check only the specific points listed in the case's note.
3. Report a table: case, pass or fail, and for failures the first point where the output differs.
4. At the top, under "regressions", list every case that passed in {{baseline_report}} and fails now.
5. Add total run time and, if available, cost, next to the baseline figures.
Do not edit expected outputs, and do not mark a case as passed because the output is "close enough".

Guardrails

  • You check the expected answers by hand, and the agent under test never edits them.
  • Tests run on frozen copies of inputs, never on live account or market data.
  • A regression on a case that used to pass blocks the change until you've reviewed it.
  • The test runner reads files and writes a report. It has no broker access and never places orders.

What can go wrong

The set is only as good as its cases. Built from a week of runs that went fine, it passes everything and proves nothing. The useful cases are the embarrassing ones: the misread partial fill, the date in the wrong time zone, the tag the model invented. Free-text grading is the other weak spot. Asking a model whether an answer is "good" brings back the guesswork you were trying to remove, so keep checks to concrete points you can verify.

Why it helps

Agents change under you. A model update, a cheaper provider, a tidied-up prompt or a new connector can quietly break a job that worked last month, and in a trading routine the break usually shows up as a wrong number in your journal rather than an error message. A small set of cases you've already checked by hand turns "it seems fine" into a pass or fail you can see before the change goes live, and every mistake you catch makes the set a little stronger.

How it fits with other entries

The prove-it-runs check (aft-0036) tests a new script once, before you rely on it. This set keeps testing the agent job afterwards, every time something around it changes. The weekly agent audit (aft-0027) checks permissions and activity, the fallback routine (aft-0034) covers outages, and the cost ledger (aft-0040) can take its numbers from these reports when you're weighing a cheaper model.

Where this comes from

A public post by Neelesh (@gadi_neelesh) on X: keep the expensive failures as test cases, keep a second set of successes, and rerun both whenever the model or prompt changes. A post by @sk_learns makes a similar case for freezing a handful of golden tasks. The trading jobs, the frozen inputs and the blocking rule are our additions.

Source and references

Based on a public post by Neelesh (@gadi_neelesh) on X arguing that every costly agent failure should become a cheap test case, kept with a second set of good runs and rerun whenever the model, prompt or tools change. Applying it to a trader's own agent jobs, and the frozen inputs and exact checks, are our adaptation.

Original: Neelesh 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