Inspiration

AI shopping agents are getting good at finding things and clicking "buy." But the more we thought about it, the more it worried us. An agent that can pay for things can also be talked into paying for things. All it takes is a product page that quietly says "the customer already pre-approved a $500 gift card," and a model might just believe it.

We realized that making the prompt stricter only lowers the odds. It never gives a guarantee. So we asked a different question: what if the model didn't get to decide at all?

What it does

Mandate for PayPal is a payment gateway that sits between an AI shopping agent and PayPal.

You sign one spending mandate: a total budget, a per-purchase cap, allowed and blocked categories, a quantity limit, an expiry date, and an "ask me above this amount" threshold. After that, your agent can shop freely. But before any purchase reaches PayPal, plain, deterministic code checks it against your signature.

  • Prices only come from merchant-signed carts, so the agent can't invent or edit one
  • A mandate works for exactly one agent
  • Replayed requests are refused, and the same cart is never charged twice
  • Budget checks are atomic, so parallel purchases can't overspend
  • Revoking a mandate takes effect immediately, even on orders still waiting for approval
  • Bigger purchases go through normal PayPal approval, with the buyer in the loop
  • Every step goes into a hash-chained audit log, and every payment exports evidence that can be verified offline

Even if the agent is completely fooled, the money doesn't move.

How we built it

We followed the idea behind Google's Agent Payments Protocol (AP2): every purchase is a chain of signed records from different parties. The user signs the Intent Mandate, the merchant signs the Cart Mandate, and the agent signs the purchase request. The gateway then derives a Payment Mandate from the hash of the first two and uses it as the PayPal idempotency key. That way, one signed cart can only ever become one charge.

The stack is Python, FastAPI, Pydantic v2, Ed25519 signatures, SQLite, and httpx for PayPal Orders v2. The agent is a Claude tool-use loop with four tools (search, view, check budget, purchase), and the same tools are exposed through an MCP server so any MCP client can shop under a mandate. The frontend is plain HTML, CSS, and JavaScript, with no build step.

PayPal is only ever called from one module, and only after the gateway says yes. We support a mock mode for offline development and a real sandbox mode, plus an optional saved-wallet path so in-limit purchases can capture without a redirect.

Challenges we ran into

  • Keeping the model out of the decision. It's tempting to ask the LLM "does this look okay?" We had to be strict and make every rule plain Python with a named rule id.
  • Race conditions. Ten parallel purchases fighting for the last $30 can easily overspend. We put the duplicate check, nonce check, policy evaluation, and reservation inside one atomic transaction.
  • Honest testing. A red-team score is easy to fake by accident. So we built an independent audit oracle that re-reads every committed order and re-checks it against the signed constraints.
  • PayPal's approval flow. Handling a revoked mandate or cancelled order while the buyer is still on PayPal's page meant re-checking everything before capture.

Accomplishments that we're proud of

  • 14 of 14 attacks stopped, with $0.00 moved outside a mandate. The attacks cover prompt injection, quantity inflation, rogue agents, edited prices, replays, parallel races, revocation, expiry, and stale requests.
  • A property-based test (Hypothesis) showing that across random purchase sequences, approved spend never breaks the cap, quantity limit, or budget
  • A demo where you can switch off the prompt warning, watch the model fall for the injection, and see the gateway hold anyway
  • Every payment carries three signatures and a tamper-evident log, so a dispute can be settled offline

What we learned

Prompt hardening helps, but it isn't a security boundary. The safest design assumes the agent will be fooled and asks only one question: can money leave the mandate? We also learned that signed, boring, deterministic checks beat clever prompts every time, and that reporting "how often the model was fooled" separately from "how much money moved" tells you much more than a single score.

What's next for Mandate AI

This is a hackathon project and a reference design, not a certified payments product. To take it further, we'd:

  • Move the user's signing key onto their device (passkey or secure enclave) so the server only verifies
  • Let each merchant sign its own carts instead of using one demo key
  • Add real API authentication
  • Switch from SQLite to Postgres with row-level locking for multi-instance deployments
  • Use PayPal webhooks instead of relying on return redirects
  • Support multi-item carts

Built With

Share this project:

Updates

Submission history