Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

In this topic

Claude
  • CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
  • Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
  • One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
  • Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
  • Hooks That Block Destructive Actions: a PreToolUse Gate That Allows, Asks or Denies
  • Choosing a Claude Code Extension: Skill, Hook, Rules File, Subagent, Slash Command or Plugin
  • Rolling Out Claude Code to a Team: Settings Precedence, dontAsk in CI, a Hook for Every-Time Rules and a Plugin for Five Repos
  • A Claude Code Review Bot in CI: Headless -p, JSON Findings, Team Rules in Git and a Person on the Merge
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Configuring MCP Servers in Claude Code: A Command or a URL, Three Scopes, and Three Moves When One Breaks
  • The Claude Messages API: Your First Call, Field by Field
  • Claude Tool Use: How tool_use and tool_result Work in the Messages API
  • Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
  • Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
  • Claude Streaming Events: The Event Order, message_stop, Tool Arguments, Stop Reasons and a WebSocket Relay
  • Images, PDFs and Thinking Blocks in the Claude Messages API: Typed Blocks In, Typed Blocks Out
  • Getting Data Into Claude: PDF Documents, the Files API, Search Results and Citations
  • Opus, Sonnet or Haiku: Pick the Claude Model per Job, and Test the Request When a New Release Arrives
  • Adaptive Thinking and Effort in Claude: Two Dials, Set per Workload, and the Thinking Block You Must Pass Back
  • Claude Cost Tracking From usage: Count Before, Cap During, Read After, Then Find the Line That Drives the Bill
  • Claude Cache Breakpoints: Where to Put cache_control, How to Move It With the Chat, and Why the Reads Stay at Zero
  • Claude Message Batches or Real Time: Choose by Who Is Waiting, Match by custom_id, Resend Only the Failures
  • Calling Claude Through Amazon Bedrock, Google Cloud and Microsoft Foundry: Same Call, Different Door
  • The Life Cycle of a Claude App: Six Phases, a Model That Retires, and a Release Gate for Every Change
  • Pinning Claude Model IDs and Upgrading Safely: One Change at a Time, a Golden-Set Replay and a Staged Rollout
  • Content Boundaries and Schema Design for Claude: Fence the Input in a Tag, Let the Output Say I Don't Know
  • The Agentic Loop and stop_reason: Keep Turning on tool_use, Stop on end_turn, Cap the Turns
  • The Claude Agent SDK: query(), ClaudeAgentOptions and @tool, in Python and TypeScript
  • Fix the Agent: Four Broken Claude Agent SDK Configs, From the Symptom to the One Wrong Line
  • Claude Managed Agents: Cloud Sandbox, Self-Hosted Sandbox or Self-Hosted Service
  • Agent SDK Hooks for Deterministic Actions: PreToolUse, PostToolUse, and Four Hooks That Fail Silently
  • Memory and Context-Window Patterns for Claude Agents: Context Editing, Compaction and the Memory Tool
  • Reading an Agent Trace: Five Signatures, Five Missing Patterns, and How Long a Fact Must Live
  • Tool Descriptions for Claude: How Claude Picks a Tool, and How to Stop It Picking the Wrong One
  • Tool Input Schemas and Error Responses for Claude: Required Fields, Enums, is_error and a Retry Flag
  • Tool Response Shaping and a Lean Tool Set: Give Claude a Sticky Note, Not the Filing Cabinet
  • Fix the Tool Schema: Read the Trace, Fix the Card, Re-Run (Four Real Schema Bugs)
  • Client Tools, Server Tools and Approval Gates: Who Runs the Tool, and Who Says Yes First
  • Built-in Tool, Custom Tool, Skill or MCP Server? Pick the Lightest One That Fits
  • System Prompt or User Turn: Where Each Instruction Goes, and Output Limits Your Code Enforces
  • Refine the Prompt One Line at a Time, Then Clean and Fence the Customer's Text
  • Prompt Revision Driven by Evals: Name the Cause, Change One Thing, Rerun the Whole Suite
  • Long-Running Sessions: Compact, Prune, Isolate or Start Fresh, Decided by Naming the Failure
  • Context Isolation Through Subagents: Read the Logs Elsewhere, Keep One Line
  • Defensive Parsing of Claude Replies: Check the Stop Reason, Read the Block or the Text, Then Validate the Values
  • Full Context or Retrieval: Choose by Corpus Size, Cost and Freshness
  • Skepticism Toward Confident Output: Check the Quote, the Record and the Sum Before You Send
  • Debugging a Claude App: Three Error Types, the Recovery Each One Earns, and the First Failing Row
  • Six Ways a 200 Can Still Be Wrong: Hallucination, Refusal, Under-Acting, Context Loss, Format Drift and Inconsistency
  • Fix the Cause, Not the Symptom: Four Recovery Drills for an LLM App, Each Checked on a New Input
  • Integration Layer or Model Output? Three Taps and Three Questions to Find Where a Wrong Answer Lives
  • Which Test Layer Owns the Failure? Unit, Functional, Integration and End-to-End Tests for a Claude App
  • Designing an Overnight Document Pipeline on Claude: Batch Lane, Live Lane, a Cached Prefix and a custom_id Reconcile
  • Proving a Model Upgrade Is Ready: A Frozen Golden Set, a Calibrated Judge, the Right Layer and a Release Gate
  • From Requirement to Design for a Claude App: Eight Requirements, Five Elements and a Trace With No Gaps
  • Build a Claude Refund App: the Messages API, Two Tools, an MCP Server and a Hook in One Loop
  • Ship a Claude App: an Eval Gate, Two Guardrail Layers, a Cost Check From usage and a Pinned Model
  • Lab: a 30-Case Golden Set, a Calibrated Judge and a Per-Slice CI Gate on a Claude Refund App
  • Lab: Cut a Claude App's Bill by 62 Percent With Usage Data, Layered Cache Breakpoints and a Batch Job
  • Lab: Three Planted Bugs in a Claude App, a Vague Prompt, a Mistyped Tool Schema and a Broken Stream Handler
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Lab: Harden a Claude App, an Uncalibrated Judge, a Retry Loop That Retries Everything and a Hook Matcher With a Gap
  • Lab: Turn a Claude App Into a Reusable Template, One Pinned Model Id, No Key in Code and Evals Built From Data
  • Building an MCP Server: Tools, Resources and Prompts in Python and TypeScript
  • MCP Transports: stdio or Streamable HTTP, and Who Starts the Server
  • Deploying and Authenticating an MCP Server: Environment Keys for stdio, Bearer Tokens and Scopes for HTTP
  1. Blog
  2. /
  3. Claude
  4. /
  5. Building with the Claude API

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.

Chaand Sheikh

·27 November 2026Building with the Claude API

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

Shape and tone pass a wrong answer well formed? valid JSON, all fields passes sounds sure? confidence: high passes matches the source? quote, record, sum blocked these two look at the reply itself this one looks at the world
A shape check and a confident tone both pass a wrong answer.

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

MoveWhat it does
Look it upQuote in the text, record exists, sum recomputed
Quote firstClaims are tied to text you can check
A way out"Not in the policy" goes to a person
High stakesA person decides

When a fluent, confident answer drives an action, pick an independent check against the source, or an "I don't know" option.

Keep going in Claude · 47 of 66

Previous
Full Context or Retrieval: Choose by Corpus Size, Cost and Freshness
Next post
Debugging a Claude App: Three Error Types, the Recovery Each One Earns, and the First Failing Row
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

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

Join free on Skool

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.

On this page

  • A driver who is always sure
  • Only one gate checks the facts
  • What we can look up
  • check.py: compare, don't guess
  • desk.py: ask, check, then send
  • Same replies, two ways
  • Asking again proves nothing
  • Give the model a way out
  • Common mistakes
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

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

Join free on Skool

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)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.