Objective
Returns processing is high-volume and decision-rich: is the return policy-eligible? Is the customer abusing returns (multiple addresses, same SKU)? Is the SKU in stock for a swap? In this recipe a returns-triage agent makes all three calls in one SQL transaction, recommending refund / replace / escalate with citations.
Step 1: Create orders + returns + policy + inventory
CREATE TABLE IF NOT EXISTS recipe_rt_orders (
order_id INTEGER PRIMARY KEY,
customer_id INTEGER,
sku TEXT,
qty INTEGER,
total_usd DOUBLE,
ordered_at TIMESTAMP,
shipped_at TIMESTAMP,
ship_to_zip TEXT
);
CREATE TABLE IF NOT EXISTS recipe_rt_returns (
return_id INTEGER PRIMARY KEY,
order_id INTEGER,
reason TEXT,
status TEXT, -- 'received' | 'denied' | 'refunded'
filed_at TIMESTAMP
);
CREATE TABLE IF NOT EXISTS recipe_rt_inventory (
sku TEXT PRIMARY KEY,
in_stock INTEGER,
reorder_at TIMESTAMP
);
CREATE TABLE IF NOT EXISTS recipe_rt_policy (
doc_id INTEGER PRIMARY KEY,
section TEXT,
body TEXT,
embedding VECTOR(384)
);
Step 2: Seed
INSERT INTO recipe_rt_orders VALUES
(8001,77,'SKU-MOUSE-WL', 1, 49.50,'2026-05-01','2026-05-02','10001'),
(8002,77,'SKU-MOUSE-WL', 1, 49.50,'2026-05-08','2026-05-09','94016'),
(8003,77,'SKU-MOUSE-WL', 1, 49.50,'2026-05-14','2026-05-15','60606'),
(8004,88,'SKU-MONITOR-4K',1, 399.00,'2026-05-12','2026-05-13','78701'),
(8005,99,'SKU-DESK-STD', 1, 549.00,'2026-05-18','2026-05-21','30301');
INSERT INTO recipe_rt_returns VALUES
(5001,8001,'arrived damaged','refunded','2026-05-04'),
(5002,8002,'changed mind','refunded','2026-05-10'),
(5003,8004,'wrong color','received','2026-05-20');
INSERT INTO recipe_rt_inventory VALUES
('SKU-MOUSE-WL', 118, NULL),
('SKU-MONITOR-4K', 3, '2026-06-15 00:00:00'),
('SKU-DESK-STD', 8, NULL);
INSERT INTO recipe_rt_policy (doc_id, section, body) VALUES
(1,'Return Window','Unopened items may be returned within 30 days of delivery for a full refund. Opened items eligible for store credit only within 14 days.'),
(2,'Damaged Goods','Damaged-in-transit returns are eligible for full refund or replacement at no cost to the customer, regardless of return window. Photographic evidence required.'),
(3,'Restocking Fee','Opened electronics carry a 15 percent restocking fee unless damaged on arrival.'),
(4,'Abuse Pattern','Customers filing 3 or more returns of the same SKU within 60 days, especially shipped to different addresses, are flagged for review. Refunds are held pending investigation.'),
(5,'Swap Eligibility','In-stock items may be swapped for color or size variants at no charge within the original return window. Out-of-stock items receive store credit.');