◉CLAUDE LABJP
●CC 2.1.332 — 2.1.332 (11/25) is still current. Skills from MCP servers appear as server:skill (beta)●OPUS 4.5 — Opus 4.5 is now scheduled to retire from the Claude API on 2027/1/22. Move to claude-opus-5-5●SONNET 4.5 — Sonnet 4.5 retires from the Claude API tomorrow, 11/30. Last day to check for hard-coded IDs●DISK — Users on Windows report Cowork's session disk filling up with no way to clean it●NEW — New: Asking Cowork for a meeting draft? Hand over old minutes after the outline is set●JETBRAINS — Our guide to using Claude with JetBrains IDEs is still among the most-read pages●CC 2.1.332 — 2.1.332 (11/25) is still current. Skills from MCP servers appear as server:skill (beta)●OPUS 4.5 — Opus 4.5 is now scheduled to retire from the Claude API on 2027/1/22. Move to claude-opus-5-5●SONNET 4.5 — Sonnet 4.5 retires from the Claude API tomorrow, 11/30. Last day to check for hard-coded IDs●DISK — Users on Windows report Cowork's session disk filling up with no way to clean it●NEW — New: Asking Cowork for a meeting draft? Hand over old minutes after the outline is set●JETBRAINS — Our guide to using Claude with JetBrains IDEs is still among the most-read pages
Articles/API & SDK
⬡ API & SDK/2026-07-11Advanced

Tightening Tool Schemas From the Arguments You See in Production

Record the arguments Claude actually passes to your tools in production, then use that distribution to add enums and patterns back into your JSON Schema. With logging code and before/after numbers.

Claude API149tool use5JSON Schemaoperations33observability21

✦ Premium Article

One morning a small notification tool was returning success while nothing was actually being sent.

The cause was an argument. My code branched on status being "done", but that day Claude was passing "完了", the Japanese word for "done." The schema only said status: string, so from the model's point of view "完了" was a perfectly valid string. Validation passed. The log said tool executed, and the branch quietly fell through.

As an indie developer running several apps at once — leaving small jobs like notifications and AdMob aggregation to Claude's tool calls — this kind of "the type is right but the meaning is wrong" gap tends to surface long after you've forgotten about it. Rejecting bad values at runtime is a reactive patch. What I want to describe here is the opposite move: observing the arguments themselves in production, then tightening the schema after the fact.

Loose schemas breed semantic drift

An argument typed only as string or number gives the model far too much latitude.

Depending on context, Claude might write "done" one day and "完了" the next, or put "high" in priority on Monday and 3 on Tuesday. Every one of those is valid JSON. And that is exactly why the gap between what the model emits and the closed set your code silently expects slips past type checking and lands in production.

Guarding with runtime validation alone keeps you a step behind. You reject, you retry, and back comes yet another spelling. Your validation-exception logs grow, but the root cause — the breadth of expression you granted the model — never shrinks.

The place to tighten is the entrance. Put an enum in the schema and the model can only choose from that set. A schema constraint bites harder than any instruction in the prompt.

First, record the arguments verbatim

To tighten anything, you first need to know what is actually arriving. Wrap your calls in a thin layer that drops each tool-use input block straight into a ledger.

import Anthropic from "@anthropic-ai/sdk";
import { appendFile } from "node:fs/promises";
 
const client = new Anthropic();
 
type ToolCallRecord = {
  ts: string;
  model: string;
  tool: string;
  input: Record<string, unknown>;
};
 
async function logToolCalls(model: string, message: Anthropic.Message) {
  const rows: ToolCallRecord[] = [];
  for (const block of message.content) {
    if (block.type === "tool_use") {
      rows.push({
        ts: new Date().toISOString(),
        model,
        tool: block.name,
        input: block.input as Record<string, unknown>,
      });
    }
  }
  if (rows.length === 0) return;
  // One JSON object per line: easy to aggregate, hard to corrupt on append
  const jsonl = rows.map((r) => JSON.stringify(r)).join("\n") + "\n";
  await appendFile("tool_calls.jsonl", jsonl);
}
 
const res = await client.messages.create({
  model: "claude-sonnet-5",
  max_tokens: 1024,
  tools: myTools,
  messages,
});
await logToolCalls("claude-sonnet-5", res);

The key is to store the values raw, without normalizing them. Normalize before recording and you erase the very spelling variance you set out to observe. The only exception is arguments that carry personal data, which you mask field by field before writing.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦A thin wrapper that records every tool_use input block verbatim, tagged with model and timestamp
✦Analyzer code that derives enums, patterns, and numeric ranges from the observed argument distribution
✦A warn-only to soft-constraint to hard-constraint rollout, and how to spot the point where over-tightening triggers empty tool calls
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ API & SDK2026-08-30
Read the Catalog Your CLI Already Ships Before Bulk-Replacing Model IDs
A newer generation makes older model IDs look stale. Here is how to pull the catalog embedded in your installed binary, sort every reference into matched, date-mismatched, and malformed, and stop the replacement that would break working IDs.
⬡ API & SDK2026-11-25
Five Days Before Sonnet 4.5 Retires: Compare the Three Things That Change Without an Error While the Old Model Still Answers
claude-sonnet-4-5 retires on November 30. Switch the ID to claude-sonnet-5-5 and nothing returns a 400, yet thinking now runs by default, max_tokens covers more than the answer, and stop_reason shifts. Here is a small script to run the same requests on both models before the old one stops answering, and how to read the differences.
⬡ API & SDK2026-11-18
Before Your Customers Pay Through Linked Billing: Reading a 402 or 403 to Find Whose Wallet Is Empty
Linked billing, released in beta on November 17, lets you choose who pays on every Claude API request through billing_policy. When a request billed to a customer comes back as a 402 or 403, here is how I work out which wallet is the cause, when to pay for it myself, and a small Python wrapper that keeps that decision in one place.