Try it: Live demo · Risk Desk · Code The demo runs on a free server, so the first load can take up to a minute while it wakes up.
How to try it in 2 minutes: pick Payee hijack → press Compare off vs on → watch the unguarded agent pay the wrong account while the guarded one pays the store → open the Risk Desk → ask the AI analyst "Explain run S0006".
Inspiration
Shopping agents are starting to create real PayPal orders, and they decide what to buy by reading web pages. A product page is text that anyone can edit: a seller note, a review, a description. I'd been working on multi-step tool attacks against AI agents, and the payment step is where those attacks stop being a curiosity and start costing money. An agent told to "respect store policies" will happily follow a seller note that says pay our fulfillment partner instead. I wanted to see how far you could get with a checkpoint in front of the PayPal API that doesn't trust the agent at all.
What it does
Spendguard puts a guard between an AI shopping agent and PayPal.
- On the way in, every product page is split into blocks and scanned by regex rules and an LLM classifier. Blocks that try to instruct an AI agent are removed before the agent reads them.
- While scanning, it tracks where every email, SKU and price came from. The user's request and the merchant catalog are trusted; page content is not.
- On the way out, every proposed PayPal order is checked: payee allowlist, catalog price match, provenance of every item and payee, high-risk items like gift cards, a per-order cap, a daily budget, and an AI judge that compares the cart with what the user asked for.
- Only orders that pass every check are created with the PayPal Orders v2 API. The person still approves on PayPal, and the server captures the payment.
The demo runs the same request twice, guard off and guard on, side by side. Without the guard, the agent creates a real sandbox order that pays an attacker's account, adds a $200 gift card hidden in an HTML comment, or pays $129 for $79 headphones. With the guard, the same agent buys the right thing from the right merchant at the right price, and the UI shows exactly which text was removed and which checks ran.
The Risk Desk
Every run lands in the Risk Desk, an audit dashboard built with AG Studio. Guard-off runs are evaluated in shadow mode: the full policy runs without being enforced. That lets the desk show how much money each attack would have cost, which check catches it, and what got through with the guard on.
- A pre-built two-page report with KPIs, charts, filters, a runs table and an evidence page
- Two custom AG Studio widgets: Exposure Split ("Spendguard cut money exposed by 100%") and Verdict Feed (colour-coded payment verdicts that cross-filter the page)
- A Spendguard theme built with Studio's theming API
- Spendguard Analyst, a custom agent on AG Studio's agent framework with five tools of its own. It can query the audit trail, explain any run, read the live policy, simulate a policy change against every recorded cart ("what if the cap were $25?"), and add charts to the dashboard.
How I built it
- Backend: Python and FastAPI. Agent runs stream to the browser over Server-Sent Events, so every tool call and guard decision appears live.
- Agent: a tool-calling loop with
search_products,get_product_pageandcreate_paypal_order. The prompt is identical in both modes; only the guard changes. - PayPal: Orders API v2 in the sandbox. OAuth client credentials,
intent: CAPTUREorders with itemised breakdowns and SKUs, an explicit payee when the agent sets one, buyer approval through the payer-action link, and capture on return. - AI: GPT-OSS 20B on Groq, through an OpenAI-compatible client. It runs the shopping agent, the injection classifier, the intent judge and the Risk Desk analyst.
- Risk Desk: React and AG Studio. A custom
AgLlmAdaptersends each model turn to the server, so the API key never reaches the browser, and the endpoint is rate-limited. - Hosting: Render, from a Blueprint in the repo.
- Tests: 33 offline tests with a scripted model and a mock PayPal client, covering every detector, every policy check, full agent runs, shadow mode and the analyst's model proxy.
Challenges I ran into
- Making the attacks realistic. Modern models shrug off crude "ignore previous instructions" text, so the injections had to read like plausible merchant notices: a payment-processor migration, a required bundle, an expired promo price.
- Deciding what to trust. The listed price and a "corrected" price in the description are both just text. Splitting the store into a trusted catalog and untrusted page content, then tracking which values came from where, is what made the payment checks precise.
- Not trusting the classifier either. The outbound checks are written so that even a completely fooled agent can't pay an unknown account or use a price that isn't in the catalog.
- Fitting an agent framework into a free-tier token budget. AG Studio's generic query tool has a 19,000-character schema, which on its own breaks Groq's 8,000-tokens-a-minute free tier. I measured every request and replaced it with compact tools of my own, bringing each analyst turn down to about 2,000 tokens.
- Small models and strict tool validation. Groq rejects any tool call that doesn't match the schema exactly, and small models improvise argument shapes. I simplified the analyst's tool arguments, made optional fields accept nulls, and had the server tell the model what was wrong and let it retry.
Accomplishments I'm proud of
- Every demo attack is stopped twice: once when the injected text is removed, and again at the payment step if anything slips through.
- Clean purchases go through untouched, so the guard isn't just blocking everything.
- Shadow mode turns "we blocked it" into "this is what it would have cost", which is what a finance or security team actually needs to see.
What I learned
The payment call is the best place to defend an agent. You can't see everything a model reads, but you can see every order it tries to create, and an order is structured data you can check exactly.
What's next
- Run the checks against live pages from the web instead of a fixture store.
- Use PayPal vaulting so the agent can pay without a redirect, with Spendguard as the only gate.
- Per-user policies and a review queue where blocked orders can be approved by a person.
- Package the guard as a library or MCP server that any agent framework can call before it touches PayPal.
Built With
- ag-charts
- ag-grid
- ag-studio
- css
- fastapi
- gpt-oss
- groq
- html
- javascript
- openai-sdk
- paypal
- paypal-orders-api
- python
- react
- render
- typescript
- vite