Inspiration
AI agents are beginning to handle payments. PayPal and its partners are already building the tools that allow agents to find products, compare options, and pay on behalf of users. But people still need a way to control how much an agent can spend, what it can buy, and where it can buy from. That control must remain in place even when an agent is tricked.
There are two main concerns. An agent could misunderstand a request, keep making purchases, or buy something the user never intended. It could also be manipulated by text hidden in product descriptions, web pages, or messages. Freelancers, small business owners, and founders are particularly exposed because they often do not have a finance team reviewing every transaction.
What it does
Leash gives AI shopping agents spending limits they cannot override.
The AI handles the shopping. It understands the user's request, searches for products, and puts together a cart. A separate policy engine, built entirely with deterministic code, checks every proposed purchase against the user's signed spending rule. It does not use AI to make financial decisions. This makes each decision predictable, testable, and easy to explain.
The process works as follows:
- The user writes a spending rule in plain English, such as "up to $60 on socks, no more than $30 per item, no more than 2 items".
- Gemini converts the rule into structured limits, including budget, categories, per-item cap, item count, merchant rating, delivery time, and expiry. The user reviews and confirms the limits.
- The server signs the confirmed limits with HMAC-SHA256 to prevent them from being changed silently.
- The shopping agent searches real products through Channel3 and proposes a cart.
- The policy engine checks the cart and returns an approval, escalation, or block decision, with the exact rules that were triggered.
- If a purchase falls outside the user's automatic approval limits but is still eligible for review, it is sent to the user for confirmation.
- Approved purchases create a PayPal order in the sandbox. The buyer approves the order on PayPal, and the server captures the payment exactly once.
- Every decision is recorded in an audit log with its reason.
Most agentic commerce demos focus on showing an agent complete a purchase. Leash also demonstrates what happens when an agent needs to be stopped.
The Security test runs the actual model and policy engine against a test catalog containing a product listing with hidden instructions. If a shopping run reads those instructions, the untrusted-origin rule blocks its proposal, regardless of the other spending limits. The audit log records why it was blocked.
PayPal handles the payment through its Orders API, including order creation and capture. The buyer approval step on PayPal provides an additional human confirmation before payment. The entire demo uses sandbox accounts, so no real money moves.
AI is also a core part of the system. Gemini turns plain-English spending rules into structured limits, which the user must confirm before they are signed. It also powers the shopping agent through tool calling. PayPal provides the payment infrastructure, while AI handles the shopping process that Leash is designed to control.
How we built it
The frontend uses React and TypeScript, with AG Grid for the audit console. Django serves the frontend and API from the same origin, allowing secure session cookies to work correctly.
The backend uses Django REST Framework and PostgreSQL, hosted on Render. The policy engine is written in pure Python. It has no AI or network dependency, handles money in integer cents, and is covered by automated tests, including the prompt injection scenario.
Budget checks run inside a database transaction that locks the spending mandate. This prevents parallel requests from exceeding the available budget. Payment capture uses a compare-and-set status change and a stable idempotency key to prevent duplicate charges.
Model output is validated like any other external input, and product descriptions are treated as untrusted data. External services are accessed through adapters with fallbacks, including a seeded product catalog when live product search is unavailable.
Challenges we ran into
- Product categories do not always match user language. A jersey was once blocked because the catalog listed it under "soccer uniforms", while the user's signed rule allowed "jerseys". The rule parser now suggests closely related category names for the user to review before signing. The policy engine remains strict.
- Model quota is limited. We designed the agent to use no more than two model calls per run. Searching and policy pre-checks are handled in code, and the system can still search without the model when the provider is unavailable.
- The model cannot be the final security check. Every path to a payment goes through one function that applies the policy engine before allowing the transaction to proceed.
Accomplishments that we're proud of
- Completed a full PayPal sandbox purchase on the live site, from writing a spending rule in plain English to capturing the payment.
- Built a security test using the real model and policy engine to demonstrate an actual block.
- Kept the policy engine simple enough to inspect and test, with every decision explained in the audit log.
What we learned
- Keep the model at the edges. AI is useful for understanding requests and proposing actions, but plain code should make every decision involving money. This made Leash easier to test and explain than relying on prompts to enforce spending limits.
- Treat everything an agent reads as untrusted. Product descriptions come from external sources. An agent can be manipulated by them, so the system must limit what it can do before that happens.
- Constraints can lead to better design decisions. The limited model quota pushed us to move product searching and policy checks into code. This reduced model usage to no more than two calls per run and made the agent more predictable.
- Real product data is not always consistent. Catalog categories often differ from the words users naturally use. Instead of weakening the rules, we made the system show related categories for users to review before signing.
- Security demonstrations should use real scenarios. We replaced a scripted attack with a live test using the actual model and policy engine. This makes the result reproducible and shows that the system can block a real proposal.
What's next for Leash
- Support for multiple agents and spending mandates per account.
- Merchant allow-lists, spending velocity limits, and category budgets over time.
- A standard interface that allows different agent frameworks to route purchases through Leash.
- Webhook-based payment reconciliation and receipts.
- User integrations.
Built With
- ag-grid-community
- channel3
- django
- django-rest-framework
- docker
- drf-spectacular
- gemini-(google-genai-sdk)
- github
- paypal-orders-api-(sandbox)
- postgresql
- react
- render-(web-service-and-postgresql)
- tanstack-query
- typescript
- vite