跳到正文
DEV Community· Muhammad Aamir Khan·· 1 小時前AI 評分53

RebutCase 如何限制 LLM 只複製指定主張來撰寫拒付回覆

I let an LLM write chargeback responses, but only by copying sentences it was given

AI 導讀

RebutCase 以可追溯的事實和模板建立拒付主張,讓 LLM 只按原文複製並串接主張,再由驗證器逐句檢查引文與數值。若所需欄位不存在,系統會捨棄該事實;草稿兩次驗證失敗或模型逾時,則改用主張生成固定文字。

正文

I'm building RebutCase, a Shopify app that helps merchants answer chargebacks. When a customer disputes a payment, the merchant gets a deadline and a set of evidence fields. Someone at the cardholder's bank reads what they send. If a single date or amount in it is wrong, the merchant has sent the bank something false.

So the hard rule from day one was: every sentence that goes to the bank must point to a piece of evidence. Here is how that ended up working, and what broke along the way.

The pipeline

collectors (Shopify data, merchant uploads)
  -> facts (normalized, keyed, sourced)
  -> checks (PASS, WARN, FAIL, NA per dispute reason)
  -> case strength (Strong, Fair, Weak)
  -> claims (deterministic templates pick facts)
  -> draft (LLM joins claims into prose, optional)
  -> verifier (every sentence cited, every value traceable)
  -> Shopify evidence fields + PDF exhibits

The core is plain TypeScript with no network calls, so every step runs against JSON fixtures in unit tests.

Facts first

A fact is { key, label, value, source, isPii }: order.created_at, tracking.delivered, payment.avs, policy.refund and so on. If a field does not exist in Shopify's API, the fact is dropped, never guessed.

Claims are templates, not generation

For a "product not received" dispute, the claims look like this:

Order {order.name} was placed on {order.created_at} for {order.items}.
The order shipped on {fulfillment.shipped_at} with {tracking.carrier}, tracking number {tracking.number}.

A claim is included only if all its facts exist. That alone removes most of the ways a response can say something untrue.

The LLM is on a very short leash

The model gets the claims with placeholders instead of personal data ({{CUSTOMER_NAME}}, {{SHIPPING_ADDRESS}}) and one job: copy every claim word for word, in order, and join two or three of them with a comma and a connector like "and" or "in addition". Every sentence ends with markers like [C2].

That sounds too strict. We started looser: rewording was fine as long as the important words were covered. Two audits found that any looser rule let a rephrase change what a claim meant. "Delivered to the shipping address on the order" can turn into "delivered to the customer" in one innocent edit, and those are different claims.

The verifier

Every sentence must:

  1. Cite at least one known claim or exhibit.
  2. Contain only dates, amounts, IDs and numbers that appear exactly in the cited facts, compared as whole values, never as substrings.
  3. Quote text and links word for word from the evidence.
  4. Avoid a banned list: accusations ("fraudulent", "lying"), outcome talk ("guarantee", "win rate"), legal threats, and the em dash.

If the draft fails verification twice, or the model times out, the app falls back to deterministic text built from the claims. The product has to work with the LLM switched off.

Merchant edits are checked too. A sentence the merchant wrote is flagged as not checked word by word, and they can still keep it.

Things the app refuses to do

  • It never submits evidence. It saves it to the dispute in Shopify, and the merchant submits, or Shopify sends it on the due date.
  • It never overwrites what Shopify pre-filled without showing a diff.
  • It never shows a win probability. Case strength is Strong, Fair or Weak, with the one to three checks that decided it.

What I would tell anyone putting an LLM near text that matters

Make the model's job as small as possible, keep the facts outside it, and write the verifier before the prompt. The adversarial cases from our audits live in a test file now, and every prompt change runs against them.

If you run a Shopify store or build for merchants, the app is at https://apps.shopify.com/rebutcase and the free guides (including 41 card network reason codes) are at https://rebutcase.zoviotech.com/reason-codes?utm_source=devto&utm_medium=article&utm_campaign=llm-verifier . Happy to answer questions about Shopify's dispute evidence API in the comments.

來源:DEV Community · dev.to