Inspiration

A PayPal dispute is a deadline and a money decision at the same time. Merchants have to read the buyer's claim, work out what evidence they actually hold, and then either accept a refund or contest. An AI that writes the answer and clicks the button is the obvious demo, and it is the wrong product: a wrong guess moves real money. We wanted the opposite split. The model reads and advises, fixed rules decide, and a person approves.

What it does

Dispute Copilot watches a merchant's PayPal sandbox disputes and prepares each one for a decision. • Ingests disputes from PayPal's Customer Disputes API, triggered by webhooks, with a full poll as a fallback. • Decides with deterministic policy. A rule engine picks accept, contest, wait or review and says which rule fired and why. The same inputs always give the same answer. • Advises with AI. A LangGraph agent classifies the buyer's claim, drafts the response, and makes its own independent recommendation. When the AI disagrees with the policy, the page says so in red. The policy decision stands. • Shows evidence honestly. Every item is labelled verified, unverified, missing or conflicting, with its source. Unverified tracking never counts as proof of delivery. • Flags risk. Repeat disputers, contradicted claims and other anomalies appear as advisory signals with plain reasons. They never change the policy decision, and they are not a fraud score. • Waits for a human. Nothing reaches PayPal until the merchant approves. The executor acts only through links PayPal itself offers on the dispute. • Records everything. Each step goes into a hash-chained audit log, so an edited entry is detectable. Telegram alerts tell the merchant about new disputes, risk flags, uncertain executions and approaching deadlines, with a link back to the dashboard. They are one-way: an alert cannot approve anything.

How we built it

Python and FastAPI for the service, LangGraph for the agent, SQLite for storage, and a server-rendered console with AG Grid Community for the queue, the audit log and the evidence view. It runs as a Docker service on Render. • PayPal: we follow the hrefs PayPal returns instead of building URLs, escalate an inquiry before providing evidence, upload evidence as multipart, and send an idempotency key (PayPal-Request-Id) on every write. • Safe execution: before acting, the executor re-checks that the dispute and the evidence snapshot (record and document hashes) are unchanged since the human approved. A timeout or 5xx leaves the proposal in an UNCERTAIN state. The app never resends on its own: it reconciles read-only against PayPal, and only then allows a retry with the same request id. • AI boundaries: the model's output is parsed and validated, it cannot change the decision, the link or the evidence plan, and drafts are stripped of links and addresses. Providers are swappable: Groq, Anthropic or a local Ollama model. The live deployment runs openai/gpt-oss-120b on Groq. • AG Grid: custom cell renderers for state, risk and amounts, the theming API, quick filter plus an external filter for status chips, saved column and filter state, a nested evidence-provenance grid, and CSV export that neutralises spreadsheet-formula characters. • Security: parsed-URL sandbox validation (an early substring check let look-alike hostnames through, and a review caught it), a strict content-security-policy, no third-party scripts, CSRF tokens, and webhook signature verification.

Challenges we ran into

• A timeout is not a failure. If PayPal does not answer a write, the refund may or may not have happened. The UNCERTAIN, reconcile and retry design came from that. • PayPal's flow has ordering rules. An inquiry has to be escalated before evidence can be provided, and link names and URL paths use different separators. We captured real sandbox responses as test fixtures. • Silent AI failure. The first live run fell back to heuristics without any error, because the model call failed quietly. We now log the provider's own error message and show which model produced each panel. Reasoning models also spend their token budget thinking, so the Groq client hides the reasoning and leaves room for the answer. • Keeping the AI useful without letting it act. The disagreement flag is the answer: the model's second opinion is visible, and it carries no authority.

Accomplishments that we're proud of

• The AI disagreement is real and visible. On a live sandbox dispute with no delivery proof, the policy said accept and the model said contest. The policy was right, and the page made the conflict obvious instead of hiding it. • Webhooks from PayPal reach the deployed service, and disputes appear in the queue without polling. Telegram alerts arrive on the merchant's phone with a link to the review page. • 213 automated tests, including browser tests and security regressions, run against fixtures captured from real sandbox responses. • The risk signals say what they are: heuristics with reasons, not a score we cannot calibrate.

What we learned

In a system that moves money, the useful question is not how much the AI can do but what it is allowed to change. Making the model advisory, the policy deterministic and the human approval a state machine meant each part could be tested on its own. We also learned to treat every model failure as something to surface, never to swallow.

What's next for Dispute Copilot

• Outcome tracking: record the final PayPal result, the amount recovered or lost, the evidence submitted and the risk signals for each dispute, so evidence strategies can be measured before any model is trained. • A real merchant order adapter in place of the demo records file. • Risk drill-down: inspect the prior disputes behind a repeat-disputer warning. • Production hardening: a multi-instance database and a live-mode review. The app is sandbox-only today and refuses non-sandbox PayPal URLs.

Built With

  • ag-grid
  • anthropic-claude-(optional-provider)
  • docker
  • fastapi
  • groq-(gpt-oss-120b)
  • langgraph
  • paypal-customer-disputes-api
  • paypal-orders-api
  • paypal-webhooks
  • playwright
  • pytest
  • python
  • render
  • sqlite
Share this project:

Updates

Submission history