Automate dispute resolution with AI using the Arbiter SDK’s evaluation hooks
The Arbiter SDK includes built-in support for AI-powered dispute resolution through evaluation hooks and a webhook handler. You can plug in any AI model — LLMs, rule engines, or hybrid systems — to automatically evaluate and decide on refund requests.
When a case needs evaluation, the handler provides a structured context:
Copy
interface CaseEvaluationContext { /** The payment information struct */ paymentInfo: PaymentInfo; /** The record index (nonce) identifying which charge */ nonce: bigint; /** Current payment state */ paymentState: PaymentState; /** Current refund request status */ refundStatus: number; /** Unique hash of the payment */ paymentInfoHash: `0x${string}`; /** Amount being requested for refund */ refundAmount?: bigint; /** Optional evidence/metadata */ evidence?: unknown;}
Use createWebhookHandler to connect your evaluation function to the arbiter:
Copy
import { createWebhookHandler } from '@x402r/arbiter';import type { CaseEvaluationContext, DecisionResult } from '@x402r/arbiter';const handler = createWebhookHandler({ arbiter, evaluationHook: async (context: CaseEvaluationContext): Promise<DecisionResult> => { // Your AI evaluation logic here const result = await myAIModel.evaluate(context); return { decision: result.shouldApprove ? 'approve' : 'deny', reasoning: result.explanation, confidence: result.confidence, }; }, autoSubmitDecision: true, // Auto-submit approve/deny on-chain confidenceThreshold: 0.9, // Only auto-submit if confidence >= 0.9});
Setting autoSubmitDecision: true calls approveRefundRequest or denyRefundRequest on-chain automatically. This submits the decision only — executing the actual refund transfer via executeRefundInEscrow is a separate step you handle after approval.
The evaluationHook function receives a CaseEvaluationContext and returns a DecisionResult. Three common patterns:
LLM-based — Send the structured context to an LLM (GPT-4, Claude, etc.) with a system prompt that outputs JSON {decision, reasoning, confidence}. Sanitize inputs to prevent prompt injection.
Rule-based — Apply deterministic rules (amount thresholds, blocklists) for predictable, high-confidence decisions. Best for clear-cut cases.
Hybrid — Apply hard rules first; if no rule matches with high confidence, fall back to LLM evaluation. Deny and flag for manual review when confidence is low.
AI-powered dispute resolution handles financial decisions. Always implement prompt injection protection, input validation, and confidence thresholds before deploying to production.