# The Pricing Guardrail — the discount that asks permission

Part of **The Engine Room** on simranjaiswal.in: five automation engines that stop money going
missing between systems. This one is a price corridor per category, enforced at the moment a quote is
written: inside the corridor a quote goes out; below it the quote asks permission, with a reason code;
below the margin floor it does not go out at all. A drift monitor watches the stream and names the rep
whose discounts are quietly growing.

Live case, with the engine running in the browser: https://simranjaiswal.in/work/pricing-guardrail

## What it does

1. **The corridor.** Per category, as a share of list price: `floor = ceil(cost / 0.9 * 100) / 100`,
   `target = floor + 0.10`, `ceiling = 1.00`. Five categories with cost 55–71% of list, so the floors
   sit at 62–79% of list.
2. **The gate, in this order.** `BLOCK` if quoted share < cost × 1.03 (below the margin floor: the
   quote is re-priced to the corridor floor and never reaches the customer). `APPROVE` if quoted share
   ≥ floor. Otherwise `NEEDS_APPROVAL` with one reason code: `VOLUME` (qty ≥ 12), else `COMPETITOR`
   (a competitor quote is attached), else `STRATEGIC` (a flagged account), else `NO REASON`, which is
   declined automatically and re-priced to the floor.
3. **The approval.** The approver answers within the 4-hour SLA with p = 0.8, otherwise the request
   escalates one level. Granted with p = 0.7 (VOLUME), 0.85 (COMPETITOR), 0.9 (STRATEGIC). Declined
   → re-priced to the floor.
4. **The drift monitor.** After a rep's 10th quote, every quote: `z = (mean of the rep's last 10
   discounts − mean of the category means of those 10 quotes) / (population sd of all discounts so far
   / √10)`. Flag when z > 2. Once flagged, a rep stays flagged; the catch records the quote index.
   The monitor cannot tell drift from habit — a rep who always discounted heavily is flagged at their
   10th quote, which is the point.
5. **Margin protected** = Σ over blocked + declined quotes of (floor − quoted share) × list × qty.
   The page shows it net of an assumption printed on the slider: re-pricing to the floor loses 15% of
   those deals, and a lost deal forgoes the margin it carried as quoted.
6. **Tie-out.** 600 = approve + granted + declined (incl. auto-declined) + escalated-granted +
   escalated-declined + blocked. If it breaks, the report is not published.

## The synthetic stream

There is no client data here. `run()` generates 600 quotes over 12 weeks from the printed rules:
12 reps with a habitual discount ~ N(0.14, 0.07) clipped 0–0.35 (the leak from the pricing case),
three of whom drift by +0.004 per quote; category, rep, quantity (1–11, or 12–20 with p 0.15), list
price per unit lognormal exp(N(9.5, 0.9)) clipped ₹2,000–₹300,000, quoted share = 1 − (habit + drift
+ N(0, 0.05)) clipped 0.45–1.0, a competitor quote attached 18% of the time, a strategic account 10%.
Randomness is mulberry32, a 32-bit generator the browser port implements bit-for-bit. The stream is
drawn first from `RNG(seed)`; the approvers' SLA and grant draws come from `RNG(seed + 1)`, so every
policy (reference, no guardrail, strict) sees the same 600 quotes. The page's reference run reproduces
`results.json` exactly (the status line says so when it does).

## Run it

```
python3 engine.py                                          # reference: seed 42, floor cost/0.9, block cost×1.03, z 2, 15% deals lost
python3 engine.py --no-guardrail                           # approve everything: the leak, undefended
python3 engine.py --floor-mult 0.85 --block-mult 1.08 --drift-z 1.5     # strict
python3 engine.py --deals-lost 0.4                         # a pessimist's net
node parity.mjs                                            # proves the browser port matches results.json
```

Stdlib only. `results.json` carries the corridor, the decision counts and ₹ values, the margin
before/after, the approval load per week, every drift catch with its z, the per-category and per-rep
tables and the decision log (first 12 quotes plus every drift catch).

## Reference run (seed 42)

See `results.json`. Headline: decisions (approve / requests granted, declined, escalated / auto-declined
/ blocked / re-priced), margin leak before → after, margin protected gross and net, approval requests per
week, and the reps the drift monitor caught with the quote at which it caught them.

## Where the shape comes from

The price corridor Simran built for a B2B medical-equipment procurement platform
(https://simranjaiswal.in/work/pricing-corridor), where a corridor per category took quote-to-order
conversion up 27%. That case found the leak after the fact; this engine is the corridor at the moment
the quote is written. Outcome figures in that case are as reported there; nothing in this repository
is a client's data.

MIT.
