A refund must belong to a paid invoice and may never exceed what remains on it. In RapScalYon these rules live in the database, where no client can skip them.

Two forms of the same rules

The invoice-refunds pack enforces its rules with triggers in Postgres, covered by about 35 test assertions. The same rules are also written declaratively for GenAI-Logic: sums for invoice totals and customer balances, formulas for line amounts, a copy for currency, constraints for the refund rules, and an event when a refund is approved.

What has been proven

The declarative rules were run in the LogicBank engine against the same scenarios as the SQL tests, and all 12 pass. That run used SQLite. It has not been run against Postgres under row-level security, and how the engine fits under per-workspace security is an open question we have put to its maintainers.

What we learned

The engine needs classic SQLAlchemy models, a session that does not expire objects on commit, and constraints that judge only rows that are new or changed. These are written up in the pack README.