---
title: Compare revised rules
description: Keep both definitions and compare the same inputs before changing your application.
icon: history
---

Before replacing a model in your application, check what changes for the cases you already understand.
Keep both model files and execute the same inputs against each. This guide performs that comparison
from your client using the public execution API. Console Replay uses separate internal operations. Neither approach relies on stored models or receipt history.

This guide uses the prepared model from the [invoice example](/docs/guides/invoice-example).

## Revise the definition you kept

There is no revision endpoint: a model change is an edit to your JSON file. Copy the model, then
increase the early-payment discount from 2% to 3% in the copy — the `0.98` multiplier in the
`payable_amount` table becomes `0.97`, and the descriptions that mention 2% are updated to match:

```bash
cp invoice-model.json invoice-model-revised.json
# In invoice-model-revised.json:
#   payable_amount table, "discount" row:  invoice_amount * 0.98  ->  invoice_amount * 0.97
#   payable_amount "desc":                 "98% of invoice_amount" -> "97% of invoice_amount"
#   payment_action "desc" and "# why" rows that say 2%:            -> 3%
#   payable_amount "# why" discount row that says 2%:              -> 3%
```

Keep the deadline, approval requirement and other outcomes unchanged. Paste the revised file into
the console’s Decision pane and run its free **Check** before executing. Keep the original file
so your application can continue using it until you choose to switch.

## Keep cases that reveal a mistake

Save these as `invoice-cases.json`. They include a qualifying invoice, the inclusive cutoff, late payments
and an invoice that needs approval.

```json
[
  {
    "name": "initial",
    "state": {
      "invoice_amount": 25000,
      "invoice_date": "2026-10-01",
      "payment_on": "2026-10-11",
      "approved": true
    }
  },
  {
    "name": "matching-json",
    "state": {
      "invoice_amount": 25000,
      "invoice_date": "2026-10-01",
      "payment_on": "2026-10-11",
      "approved": true
    }
  },
  {
    "name": "past-cutoff",
    "state": {
      "invoice_amount": 25000,
      "invoice_date": "2026-10-01",
      "payment_on": "2026-10-12",
      "approved": true
    }
  },
  {
    "name": "unapproved",
    "state": {
      "invoice_amount": 25000,
      "invoice_date": "2026-10-01",
      "payment_on": "2026-10-11",
      "approved": false
    }
  },
  {
    "name": "early-40000",
    "state": {
      "invoice_amount": 40000,
      "invoice_date": "2026-10-01",
      "payment_on": "2026-10-06",
      "approved": true
    }
  },
  {
    "name": "late-9000",
    "state": {
      "invoice_amount": 9000,
      "invoice_date": "2026-10-01",
      "payment_on": "2026-10-13",
      "approved": true
    }
  }
]
```

## Compare both models from your client

Save this as `compare-invoices.mjs` and run `node compare-invoices.mjs`. Each execution sends the complete
definition and matching JSON to `POST /v1/systemone`, at the single execution rate. Compare the three invoice outcomes; a revised model may also return helper decisions. Both sets of receipts are kept in your output file.

```js
import { readFile, writeFile } from "node:fs/promises";

const read = async path => JSON.parse(await readFile(path, "utf8"));
const original = await read("invoice-model.json");
const revised = await read("invoice-model-revised.json");
const cases = await read("invoice-cases.json");
const outcomes = ["payment_action", "payable_amount", "discount_by"];
const values = answers => Object.fromEntries(outcomes.map(key => {
  const answer = answers[key];
  if (!answer) throw new Error(`Missing answer: ${key}`);
  return [key, answer[answer.type]];
}));

async function execute(model, state) {
  const response = await fetch("https://api.aityx.ai/v1/systemone", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.AITYX_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ decision: model, state }),
  });
  const result = await response.json();
  if (!response.ok) throw new Error(result.detail ?? `aityx ${response.status}`);
  return result;
}

const comparison = [];
for (const test of cases) {
  const before = await execute(original, test.state);
  const after = await execute(revised, test.state);
  const oldValues = values(before.answers);
  const newValues = values(after.answers);
  const changed = [...new Set([...Object.keys(oldValues), ...Object.keys(newValues)])]
    .some(key => oldValues[key] !== newValues[key]);
  comparison.push({ name: test.name, state: test.state, changed,
    before: oldValues, after: newValues,
    receipts: { before: before.receipt, after: after.receipt } });
}
await writeFile("invoice-comparison.json", JSON.stringify(comparison, null, 2));
console.table(comparison.map(({name, changed, before, after}) => ({
  case: name, changed, before: before.payable_amount, after: after.payable_amount,
})));
```

Under the written invoice policy, three payable amounts should change: the two qualifying $25,000 cases
move from $24,500 to $24,250, and the early $40,000 case from $39,200 to $38,800. Late and unapproved cases
should keep their original outcomes. Review any unexpected difference before switching.

## Choose what your application submits

Deploy the revised model file when the comparison meets your expectations. Keep the original for rollback.
Changing the model in your console session does not change the definition submitted by your application.

If a rule disagrees with the policy, add the failing case to your case file first, then edit the
definition until the comparison matches your expectations. There is no server-side model or feedback history: keep that evidence with your own tests.
