QWED-UCP
Verify AI-driven commerce transactions before they reach payment.What is QWED-UCP?
QWED-UCP provides deterministic verification guards for the Universal Commerce Protocol (UCP) - Google’s open standard for AI-driven commerce.The Problem
When AI agents shop on behalf of users, they can make calculation errors that result in:- 💸 Wrong totals - Customers overcharged or undercharged
- 📉 Bad discounts - Percentage calculations off
- 🧾 Incorrect tax - Legal compliance issues
- 💱 Currency errors - International payment failures
The Solution
QWED-UCP intercepts checkout requests and mathematically verifies every calculation before payment:How It Works
The 6 Guards
| Guard | What It Verifies | Error When Wrong |
|---|---|---|
| Money Guard | total = subtotal - discount + tax | ”Calculated 98.25, Agent claimed 100.00” (Checked via SymPy) |
| State Guard | Valid checkout state transitions | ”Invalid transition: completed → incomplete” (Checked via Z3 Solver) |
| Schema Guard | UCP JSON schema compliance | ”Missing required field: currency” |
| Line Items Guard | price × quantity = line_total | ”Line item mismatch: 2 × 65” |
| Discount Guard | Percentage and fixed discount math | ”10% of 10, not $15” |
| Currency Guard | ISO 4217 codes, JPY no-decimals | ”JPY cannot have decimal amounts” |
Installation
Python (PyPI)
Node.js (npm)
Quick Start
Basic Verification
Middleware Integration (FastAPI)
Middleware Integration (Express.js)
GitHub Action (CI/CD)
Use QWED-UCP as a GitHub Action to audit transaction logs in your CI/CD pipeline.Installation
Add to your workflow (.github/workflows/commerce-audit.yml):
Parameters
| Input | Description | Default |
|---|---|---|
log_path | Path to transaction JSON logs | ./logs/ |
strict_mode | Fail on any violation | true |
tolerance | Rounding tolerance (cents) | 0.01 |
What Gets Audited
The Action scans all.json files in the specified path and verifies:
- ✅ Line item math:
price × quantity = total - ✅ Discount calculations
- ✅ Tax amounts
- ✅ Currency format (ISO 4217)
- ✅ No “Penny Slicing” (rounding theft)
Example Output
Why QWED-UCP?
Business Impact
| Scenario | Without QWED-UCP | With QWED-UCP |
|---|---|---|
| AI miscalculates 10% discount as 15% | Customer overcharged $5 | ❌ Blocked, 422 returned |
| Tax calculation rounds wrong | Legal audit issues | ✅ Caught before payment |
| Currency format invalid | Payment gateway rejects | ✅ Caught at middleware |
| State transition invalid | Order stuck in limbo | ✅ Proper error message |
ROI Calculation
For a platform processing 100M transactions/year:- Error rate without verification: ~0.1%
- Errors per year: 100,000 transactions
- Average error cost: $6.39 (dispute handling + refunds)
- Potential loss: $638,700/year
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
QWED_UCP_STRICT | Fail on any schema mismatch | true |
QWED_UCP_LOG_LEVEL | Logging level | INFO |
QWED_UCP_TOLERANCE | Tolerance for rounding (cents) | 0.01 |
Custom Guard Configuration
Next Steps
- Guards Reference - Deep dive into each guard
- Examples - Real-world use cases
- FastAPI Middleware - Python integration
- Express.js Middleware - Node.js integration
- Troubleshooting - Common issues
Links
- GitHub: QWED-AI/qwed-ucp
- PyPI: qwed-ucp
- npm: qwed-ucp-middleware
- UCP Protocol: developers.google.com/commerce/ucp