Inspiration
When a contractor or DIYer snaps a photo of a renovation job (like resurfacing a worn 96 x 25-inch kitchen countertop), turning that image into a verified, budget-compliant purchase across multiple suppliers takes hours of manual math, tab-switching, and SKU checking.
SpecToCart turns any project photo into a policy-verified, itemized PayPal order, backed by a complete, auditable rejection log, in one click.
What it does
SpecToCart takes a photo of a physical project (a worn countertop, a bare wall, a broken fixture) and outputs a sourced, budget-enforced shopping cart ready for PayPal settlement:
- Vision-to-BOM Extraction: Gemini Vision analyzes the photo and outputs a structured Bill of Materials (3-5 items), each with a target quantity, per-item price cap, and priority tier (
Essentialvs.Optional). - Deterministic Project Math: Instead of letting an LLM guess quantities, a Python math engine computes exact material needs from real dimensions:
ceil((area * 1.10 waste) / coverage). - Audited Retail Sourcing: Channel3's product graph sources each item at or under its price cap. Every candidate is scored for relevance, checked for a mandatory head-noun match, and, if disqualified, logged with an explicit rejection code (
price_over_cap,currency_mismatch,insufficient_relevance,head_noun_missing,score_zero). - AI Category Critic Pass: A second Gemini call per item verifies whether the winning SKU is plausibly the right product category, catching semantic traps that keyword overlap misses (e.g., rejecting a solid silicone seam cover when the BOM calls for liquid silicone sealant).
- Deterministic Budget Fallback: If the cart exceeds the spend cap, a fixed-policy fallback drops
Optionalitems in deterministic order (ascending relevance, descending line total) and logs every removal. - Verified PayPal Settlement & Reconciliation: The approved cart becomes an itemized PayPal Sandbox order with idempotency keys and the project photo's SHA-256 hash bound to
custom_id. Post-capture, a two-column Reconciliation Certificate displays PayPal settlement data alongside the full Channel3 rejection audit trail (downloadable as JSON). - One-Click Repeat Checkout: Returning builders use PayPal Vault v3 to settle subsequent projects in one click without a browser popup, backed by a signature-verified webhook endpoint for asynchronous confirmation.
How we built it
- AI & Validation: Gemini 3.6 Flash (with 3.8 fallback) via
google-genai, strict Pydantic schema enforcement for BOM extraction, install step-plans, and the per-item critic pass, wrapped in a two-tier retry chain for transient503errors. - Deterministic Core (Python): All arithmetic (project math, relevance scoring, and budget fallback) runs in pure Python. The model never guesses; the code computes.
- Live Retail Graph: Channel3 product graph for real-time sourcing, with schema verified empirically before trusting the pipeline to transact.
- PayPal Orders v2, Vault v3 & Live Webhooks: Flask backend integrating PayPal Orders v2 with idempotency and PayPal Vault v3 live and proven (real billing token
BA-0DC55606G6021210Dsettling a second$49.79charge headlessly without a browser popup). Signature-verified webhooks are live with threeSUCCESSevents, and refunds are provenCOMPLETEDtwice. Every capture is audited down to the cent (gross$49.79, fee$2.23, net$47.56), with the Reconciliation Certificate bound to both the photo's SHA-256 hash and the Idempotency Key. - Spend Policy Gate & Live Rebudgeting: Built an interactive spend-policy gate that enforces budget caps in real time. Toggling the cap to
$48triggers an automatic trim to$45.54by droppingOptionalitems in deterministic policy order, while dynamically recalculatingTOTAL Qtyas the exact sum of item quantities. - Procurement Grid: AG Grid Community v31.3.2 (Quartz Dark theme) for the interactive manifest, featuring priority badges, red-tinted rows for Critic rejections, a dedicated Critic verdict column (
✗ REJECT/✓ passwith hover reasons), pinned totals, column filters, custom currency formatting, and one-click CSV export. - Interactive CFO Audit Studio: AG Studio 3.1.0 (layout
V9) embedded directly below the cart, featuring a$49.79KPI card, a vertical spend-breakdown column chart, bidirectional cross-filtering, Drill Through inspection, live Total Row aggregation, and instant switching between Edit and executive View modes with auto-saved layouts.
Challenges we ran into
- Transient Gemini 503s: Hit
503 UNAVAILABLEspikes during peak load. Built a two-tier retry chain with exponential backoff and automatic in-family model fallback. - Spurious Retail Keyword Matches: Cheapest is rarely correct. Possessive brand names tokenized into
["elmer", "s"], allowing single-letter"s"matches, and"marble wall sticker"beat"vinyl wrap"on two shared words. Solved this with query-length-scaled minimum-match thresholds and strict head-noun enforcement. - Semantic Category Mismatches: Even with strong token overlap, a silicone seam cover scored as a winner for liquid silicone sealant. Rather than silently substituting a bad SKU, we added the second-pass Gemini category critic and
NoValidOfferErrorto flag and block mismatches before checkout. - Sandbox Merchant & Webhook Setup: Configured a US Business sandbox merchant and Developer Dashboard webhook listener to independently verify both browser-present checkouts and buyer-not-present vaulted captures.
Accomplishments that we're proud of
- Full End-to-End Proof: Working
Photo -> BOM -> Sourcing -> Critic -> PayPal Capturepipeline with committed transaction artifacts. - 35 Passing Tests: Pure-function unit test coverage across project math, relevance scoring, budget fallback, and idempotency.
- Dual PayPal Verification: Independently verified browser-present capture, headless Vault v3 capture (
BA-0DC55606G6021210D), threeSUCCESSwebhook events withevent.iddeduplication, and twoCOMPLETEDrefunds. - Zero-Trust Auditability: A downloadable Reconciliation Certificate (gross
$49.79, fee$2.23, net$47.56) that lets any judge re-derive every sourcing and budget decision without even watching the demo video.
What we learned
Deterministic pipelines beat autonomous loops for procurement. Fixed control flow makes arithmetic testable and receipts reproducible. The real differentiator isn't building another "shopping agent"; it's building the derivation and spend-control layer (project math, rejection logs, and deterministic fallback) that a generic agent structurally cannot produce. Flagging and blocking a bad SKU is far more trustworthy than blindly auto-filling a cart.
What's next for SpecToCart
- Single-Store Cart Optimization: Consolidating orders by merchant as cross-merchant grouping becomes available in Channel3.
- Smart Optional Substitution: Swapping
Optionalitems for lower-cost alternatives before dropping them under tight budgets. - Multi-Room Manifests: Expanding the Python project-math engine to handle wall coverage, flooring, and electrical fixtures.
- Enterprise Spend Policy: Spec-match scoring for automated SKU substitution under corporate procurement rules.
Best Use of Channel3
SpecToCart treats Channel3 as a governed sourcing layer, not just a search bar.
For every BOM item, SpecToCart queries Channel3 with a per-item price cap and stock filter, then evaluates every returned candidate against a strict relevance engine (scaled minimum word matches + mandatory head-noun match). Every candidate Channel3 returns is persisted in the run receipt alongside its relevance score, matched tokens, and explicit rejection reason, turning the output into a complete procurement audit trail rather than a simple success log.
To catch edge cases that keyword scoring cannot distinguish (e.g., silicone seam cover vs. silicone sealant tube, or glue gun vs. heat gun), a per-item Gemini critic pass validates the winning Channel3 offer's category.
Finally, we empirically verified Channel3's raw JSON schema (id, title, description, offers[]{url, domain, price{price, currency}, availability}, category, variants, confirming buy_url lives at offers[0].url) using DEBUG_CHANNEL3=1 before authorizing purchases. When no candidate passes, the pipeline raises NoValidOfferError instead of silently buying the wrong product.
Best Use of AG Grid
In SpecToCart, AG Studio 3.1.0 and AG Grid Community v31.3.2 work together as a unified spend-control and executive audit suite. The grid governs the spend; the Studio presents it.
- Centerpiece: Interactive CFO Audit Studio (AG Studio 3.1.0, Layout V9): Directly below the cart, the verified manifest feeds a live, executive-ready AG Studio canvas featuring a
$49.79KPI card, an itemized data table, and a vertical spend-breakdown column chart. Bidirectional cross-filtering links the chart and table in both directions: clicking any bar (such as the primary cost driver, the Marble Roll at $33.56) filters the table instantly, and selecting rows in the table updates the chart. Drill Through lets reviewers inspect underlying line-item details on demand, while a live Total Row dynamically recalculates its aggregation to follow whatever filter is active. Users can customize the dashboard in Edit mode and switch cleanly to View mode, with every layout change auto-saved and restored. - Audit-First Procurement Grid (AG Grid 31.3.2, Quartz Dark): Above the Studio, the interactive manifest uses flexible column sizing (
BOM Specflex1.3,Channel3 Winnerflex1.5), custom currency formatting, instant sorting/filtering, full-text hover tooltips (nothing hidden behind...), a pinned cart-totals row (TOTAL Qtyas sum of quantities), one-click CSV export, and custom cell renderers for color-coded priority badges (Essentialin blue,Optionalin grey). - Inline AI Critic & Rejection Drawers: A dedicated Critic Verdict column surfaces
✗ REJECT(red) and✓ pass(green) with the AI's reasoning on hover, while tinting rejected rows red. Expanding any row opens its Rejection Drawer, exposing every losing Channel3 candidate, its relevance score, and its exact rejection reason. - Live Policy Control: Toggling the budget cap from $150 to $48 reshapes the grid in real time, dropping the
Optionaldegreaser and recalculating the total from $49.79 to $45.54. An approval checkbox directly gates the PayPal checkout button, ensuring no payment executes until the policy-checked grid is approved.
Built With
- ag-grid
- channel3
- flask
- gemini
- javascript
- paypal
- pydantic
- python