
The demo uses a bug that refunds the same order twice. Perch flags the unguarded function, and the check passes once the guard is added. The requirement stays in perch.yaml, so you can check a later agent edit against the same rule. Full command output.
Add the requirement
Once you have set up Perch, save this as refund.py in a Git repository:
def refund(order, payment):
payment.refund(order.total)
order.status = "refunded"
return order
Add the behavior you need as a rule:
$ perch rules add refund-once --where refund.py --each method --ensure "Refunded orders cannot be refunded again."
Added refund-once.
That saves the rule in perch.yaml. Now check the function against it:
$ perch check refund.py::refund --rules refund-once
refund.py:1 refund
1 check, 1 broken.
Confidence Rule Description
80% refund-once Refunded orders cannot be refunded again.
This output is from the September 20 demo. The check exited with 3, which means Perch found something.
Add the guard
Return early, before calling the payment provider, if the order has already been refunded:
def refund(order, payment):
if order.status == "refunded":
return order
payment.refund(order.total)
order.status = "refunded"
return order
Run the same command again on the edited file:
$ perch check refund.py::refund --rules refund-once
refund.py:1 refund
1 check, nothing to report.
This time it exited with 0. perch check reads the file on disk, so you do not need to commit the fix first. Each check asks the model again, so your scores may differ.
Check the payment behavior
Add a regression test that refunds the same order twice and checks that the payment provider was called only once. Also test a failed refund at the provider: the order must not end up marked as refunded.
The guard only covers calls made one after another. Two requests at the same time, or a crash after the payment succeeds, need idempotency at the provider and durable state; test those at the payment boundary.
Run the rule in CI
Commit the rule alongside the code. With origin/main fetched, scan the changes on your branch:
perch scan --since origin/main --filter type=lint
Have your coding agent run the single-function check after its edits too. Agent setup adds Perch instructions to supported coding assistants, and the same rules can fail AI slop pull requests in CI.