simodocs

Examples

Auto-approve refunds safely

Approve refunds automatically only when the request clearly meets the policy, decline the clear no's, and send everything in between to a person. Because the probabilities are calibrated, the thresholds translate directly into an error rate.

from simoai import Client, Fill, Noul

c = Client()

POLICY = """Refunds are allowed within 30 days of delivery for items that arrived damaged or not as described.
Opened software and gift cards are not refundable. Refunds over $500 need a manager."""

def decide(ticket: str, order: dict) -> str:
    r = c.ask(
        {"policy": POLICY, "order": order, "ticket": ticket},
        {
            "eligible": Noul("The refund request meets the policy"),
            "amount":   Fill("the amount the customer wants refunded, in dollars", kind="number"),
            "fraud":    Noul("The request shows signs of fraud or abuse"),
        },
        two_pass=True,   # read the amount first, then decide with it in view
    )
    p, amount = r["eligible"].noul, r["amount"].parsed
    if r["fraud"].noul > 0.3:
        return "review: possible abuse"
    if amount is not None and amount > 500:
        return "review: needs a manager"
    if p > 0.97:
        return f"approve ${amount}"
    if p < 0.05:
        return "decline"
    return f"review: eligible p={p:.2f}"

print(decide("The blender arrived with a cracked jug. I'd like my money back.",
             {"item": "Blender", "price": 89, "delivered": "2026-10-09", "today": "2026-10-18"}))
# approve $89.0

Choosing the thresholds

Set each threshold from what a mistake costs, and let the calibration tell you the trade-off:

Threshold to approve Wrong approvals among those approved near the threshold Share sent to people
0.90 about 1 in 10 lower
0.97 about 3 in 100 medium
0.99 about 1 in 100 higher

Log every decision with its probability, then check a sample: approvals made at 0.97 should be right about 97% of the time. The business rules (manager over $500, the fraud flag) stay in your code, where they are exact.