CLAUDE LABJP
SONNET — Claude Sonnet 5 is now the default model in Claude Code, with a native 1M-token context window and introductory pricing through August 31CHROME — Claude in Chrome reaches general availability, letting you hand browser work directly to ClaudeCOWORK — Cowork expands to mobile and web so sessions and files follow you across devices, starting in beta for Max usersDATAVIZ — Claude Code adds a /dataviz skill offering guidance for designing charts and dashboardsAGENTS — Agent workflows gain background notifications, draft PR handoff, and improved failoverENTERPRISE — Claude Enterprise adds richer admin analytics, model-level entitlements, and spend alertsSONNET — Claude Sonnet 5 is now the default model in Claude Code, with a native 1M-token context window and introductory pricing through August 31CHROME — Claude in Chrome reaches general availability, letting you hand browser work directly to ClaudeCOWORK — Cowork expands to mobile and web so sessions and files follow you across devices, starting in beta for Max usersDATAVIZ — Claude Code adds a /dataviz skill offering guidance for designing charts and dashboardsAGENTS — Agent workflows gain background notifications, draft PR handoff, and improved failoverENTERPRISE — Claude Enterprise adds richer admin analytics, model-level entitlements, and spend alerts
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 API112tool use5JSON Schema2operations14observability19

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-06-16
Trusting Claude's Structured Output in Production — Validation Gates and Repair Loops
When Claude's structured output breaks 'occasionally' in production, combine tool-use enforcement, a schema validation gate, a single repair loop, and a graceful degradation fallback to eliminate broken JSON from your operations — with working TypeScript code.
API & SDK2026-07-04
Reading the Claude apps gateway Announcement, I Rebuilt My Indie-Scale Control Plane
The self-hosted Claude apps gateway is a control-plane/data-plane separation you can scale down. Per-app cost attribution, model allowlists, and fail-closed spend caps, implemented as a small Cloudflare Workers proxy.
API & SDK2026-06-29
Let Claude Actually See the Images Your Tools Return — Use Image Blocks in tool_result and Cut Tokens by Roughly 10x
Stuffing a base64 string into a tool_result makes the same image cost roughly 10–20x more tokens. Here is how to return it as an image content block instead, with SDK code, a token-cost estimate, and the gotchas I hit in production.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →