Skip to content
Luciano Fried
ENES

Back to selected work

Project

Card Dispute Agent

A provider-agnostic card-dispute agent on a hexagonal core: a typed Pydantic classifier decides how to handle each claim, no refund goes out without human approval, and every call is measured for tokens, latency, and cost.

  • IN PROGRESS
  • Private repository

Stack

  • Python
  • Pydantic
  • Hexagonal Architecture

Description

Building an agent that handles card-dispute claims, architecting the foundation first. A hexagonal core keeps the domain provider-agnostic: it depends on an async LLMProvider port with swappable adapters and imports no vendor SDK, a boundary enforced by architecture tests that run in CI. A typed Pydantic classifier decides the action for each claim — investigate it, request missing information, answer a question about the applicable regulations, or decline — and human approval is mandatory before any refund. A three-layer prompt-injection defense is validated against the real provider, not only a mock, and a local/cloud router keeps sensitive data (card numbers, tax IDs, national IDs) off the cloud. Answers about the applicable regulations come from a retrieval pipeline over Argentine financial regulation and internal policies, built on Qdrant with local embeddings and evaluated against a 32-case golden dataset (Hit@1, Recall@5, MRR). Every call is instrumented for tokens, latency, and cost — the basis for a benchmark of 14 cloud and local configurations — and provider quotas are managed with rate limiting and bounded retry with backoff, implemented as composable decorators.

Highlights

  • Designed a provider-agnostic hexagonal architecture (Gemini and Ollama) with async LLMProvider, Embedder and Retriever ports, swappable adapters, and architecture tests in CI that keep the domain free of SDK dependencies.
  • Built a structured-output complaint classifier with Pydantic, a three-layer prompt-injection defense, and a local/cloud router that never sends sensitive data (card numbers, tax IDs, national IDs) to the cloud and escalates cases that need it to human review.
  • Built a retrieval pipeline over Argentine financial regulation (Law 25.065, Central Bank rules) and internal policies using Qdrant and local embeddings, evaluated against a 32-case golden dataset (Hit@1, Recall@5, MRR).
  • Benchmarked 14 cloud vs. local configurations (Gemini vs. Qwen 3.5) on accuracy, latency and cost, and managed provider quotas with rate limiting and bounded retries with backoff, implemented as composable decorators.

Architecture

Dispute claim → three-layer prompt-injection defense → typed Pydantic classifier (investigate, request information, answer about the regulations, or decline) → mandatory human-approval gate before any refund → async LLMProvider port, with no vendor SDK inside the domain → composable decorators for rate limiting and bounded retry with backoff → swappable provider adapters. Architecture tests run in CI and fail the build if an infrastructure import leaks into the domain. Tokens, latency, and cost are measured on every call.