Skepticism Toward Confident Output: Check the Quote, the Record and the Sum Before You Send
A refund desk gets four equally confident replies. Three are wrong: an invented quote, a wrong sum and an order that doesn't exist. Three small lookup checks hold all three, and asking the model if it's sure catches none.
What you will learn
- Explain why a well-formed, confident reply can still be wrong
- Write checks that compare a reply with things you can look up: a quote, a record and a recomputed total
- Hold a reply that fails a check instead of sending it, with the reason
- Give the model a way out so it says 'not in the policy' instead of inventing
Before you start
- Defensive parsing of Claude replies
- Basic Python and JSON
A reply can be well formed, calm and sure of itself, and still be wrong. A customer asks the refund desk assistant: Can I return a sale item? The reply: Yes, within 45 days. Confidence: high.
Now look at the policy. Sale items are final sale and cannot be returned. Sounding right isn't a check. This article shows the checks that are.
A driver who is always sure
A taxi driver says "left at the bridge, I'm sure", "right at the mill, I'm sure", "straight through the tunnel, I'm sure". The passenger checks the map. The first two turns are right; the tunnel isn't. The voice never changed. Confidence tells you about the driver's manner, not about the road.
Only one gate checks the facts
What we can look up
The refund desk has two sources it controls. The policy text:
Refund policy
1. Items may be returned within 30 days of delivery.
2. Sale items are final sale and cannot be returned.
3. Refunds go back to the original payment method.
4. Shipping fees are not refunded.
5. Damaged items are replaced or refunded at no cost.
And the order records, orders.json:
{
"A-101": {"item": "mug", "qty": 2, "price": 8.00, "status": "delivered"},
"A-102": {"item": "notebook", "qty": 3, "price": 12.50, "status": "delivered"},
"A-103": {"item": "lamp", "qty": 1, "price": 34.00, "status": "shipped"}
}
The model replies as JSON with an answer, a quote, an order and a total.
check.py: compare, don't guess
"""Three checks that compare a model reply with things we can look up."""
def check(reply, policy, orders):
"""Return a list of problems. An empty list means every check passed."""
problems = []
quote = reply.get("quote")
if quote and quote not in policy:
problems.append("quote is not in policy.txt")
order = reply.get("order")
if order and order not in orders:
problems.append(f"order {order} is not in orders.json")
if order in orders and reply.get("total") is not None:
real = orders[order]["qty"] * orders[order]["price"]
if abs(reply["total"] - real) > 0.001:
problems.append(f"total {reply['total']:.2f}, order says {real:.2f}")
return problems
- The quote must appear word for word in the policy. If it isn't there, the model made it up.
- The order must exist in our records.
- The total is recomputed from the order, quantity times price, not believed.
desk.py: ask, check, then send
def decide(question, system=SYSTEM):
"""Ask once, then check the reply against what we can look up."""
reply = json.loads(ask(question, system))
if reply["answer"] == "Not in the policy.":
return "PERSON not in the policy, ask a person"
problems = check(reply, POLICY, ORDERS)
if problems:
return "HELD " + problems[0]
return "SENT"
Every reply goes through check before it's used, not after. A problem means the reply is held, with the reason. Only a reply with no problems is sent.
Same replies, two ways
The replies come from a stand-in on a mock transport. Each one is scripted to sound equally sure, and some are wrong on purpose; it imitates a model, it isn't one.
trusting every reply:
Q1 SENT 30 days from delivery.
Q2 SENT Yes, within 45 days.
Q3 SENT You get 42.50 back.
Q4 SENT Yes, it shipped on Tuesday.
checking every reply:
Q1 SENT
Q2 HELD quote is not in policy.txt
Q3 HELD total 42.50, order says 37.50
Q4 HELD order A-777 is not in orders.json
Trusting sends all four. Checking sends one and holds three, each for a reason: an invented quote, a wrong sum (3 notebooks at 12.50 is 37.50, not 42.50) and an order that doesn't exist. The checks are a few lines of code. They compare; they don't guess.
Asking again proves nothing
A common shortcut is to ask the model whether it's sure:
asking the model to grade itself:
Q2 Can I return a sale item? -> Yes, I am sure.
The same wrong answer, now with more confidence. A model that says it's sure has told you its tone, not its evidence. The fix is to look it up: is the "45 days" quote in the policy file? No. That's a fact, not a feeling.
Give the model a way out
Checks catch an invention. You can also make one less likely. Gift cards aren't in the policy at all. With the plain system prompt, the model invents an answer with a quote the policy doesn't contain. The second prompt adds one sentence:
SYSTEM = "Answer from the refund policy. Reply as JSON."
SYSTEM_OPEN = SYSTEM + " If the policy does not say, answer: not in the policy."
a way out, on a question the policy does not answer:
Q5 plain prompt HELD quote is not in policy.txt
Q5 with a way out PERSON not in the policy, ask a person
With a way out, the gift-card question goes to a person and nothing is invented. Make "I don't know" an easy answer and the model doesn't have to make one up. For document-grounded answers, the same idea becomes a not-found status, covered in citations and abstention in RAG.
Common mistakes
- Treating a confidence field as evidence. It's part of the reply, so it can be wrong too.
- Asking "are you sure?" It asks the same source to grade itself.
- A bigger model as the fix. It may be wrong less often, but it's still unchecked.
- Checking after sending. The customer finds out at the counter.
Recap
| Move | What it does |
|---|---|
| Look it up | Quote in the text, record exists, sum recomputed |
| Quote first | Claims are tied to text you can check |
| A way out | "Not in the policy" goes to a person |
| High stakes | A person decides |
When a fluent, confident answer drives an action, pick an independent check against the source, or an "I don't know" option.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
Claude Certified Developer - Foundations (CCDV-F) Exam Prep
Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.