●SONNET — Claude Sonnet 5 is now the default model in Claude Code, with a native 1M-token context window and introductory pricing through August 31●CHROME — Claude in Chrome reaches general availability, letting you hand browser work directly to Claude●COWORK — Cowork expands to mobile and web so sessions and files follow you across devices, starting in beta for Max users●DATAVIZ — Claude Code adds a /dataviz skill offering guidance for designing charts and dashboards●AGENTS — Agent workflows gain background notifications, draft PR handoff, and improved failover●ENTERPRISE — Claude Enterprise adds richer admin analytics, model-level entitlements, and spend alerts●SONNET — Claude Sonnet 5 is now the default model in Claude Code, with a native 1M-token context window and introductory pricing through August 31●CHROME — Claude in Chrome reaches general availability, letting you hand browser work directly to Claude●COWORK — Cowork expands to mobile and web so sessions and files follow you across devices, starting in beta for Max users●DATAVIZ — Claude Code adds a /dataviz skill offering guidance for designing charts and dashboards●AGENTS — Agent workflows gain background notifications, draft PR handoff, and improved failover●ENTERPRISE — Claude Enterprise adds richer admin analytics, model-level entitlements, and spend alerts
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.
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.
Once you have days or weeks of JSONL, look at the value distribution per field. There are three things to decide: is it a closed set (→ enum), is the format uniform (→ pattern), and does the numeric range converge (→ minimum / maximum)?
import { readFileSync } from "node:fs";type FieldStats = { count: number; values: Map<string, number>; numeric: number[];};function analyze(path: string, tool: string) { const stats = new Map<string, FieldStats>(); for (const line of readFileSync(path, "utf8").split("\n")) { if (!line) continue; const rec = JSON.parse(line); if (rec.tool !== tool) continue; for (const [k, v] of Object.entries(rec.input)) { const s = stats.get(k) ?? { count: 0, values: new Map(), numeric: [] }; s.count++; const key = String(v); s.values.set(key, (s.values.get(key) ?? 0) + 1); if (typeof v === "number") s.numeric.push(v); stats.set(k, s); } } for (const [field, s] of stats) { const distinct = s.values.size; const suggestion: string[] = []; // A small, converged value set is an enum candidate if (distinct <= 8 && s.numeric.length === 0) { suggestion.push(`enum: [${[...s.values.keys()].map((x) => `"${x}"`).join(", ")}]`); } if (s.numeric.length > 0) { suggestion.push(`min=${Math.min(...s.numeric)} max=${Math.max(...s.numeric)}`); } console.log(`${field}: distinct=${distinct} count=${s.count} => ${suggestion.join(" / ") || "no constraint"}`); }}analyze("tool_calls.jsonl", "send_notification");
Here is where the Japanese value in status becomes a number you can see. In my case roughly 6% of calls used "完了" and the rest "done" — a UI string leaking straight into the argument.
Tighten in stages
Seeing the distribution is not a license to slam a hard enum on immediately. A legitimate value may simply not have appeared during your observation window, and over-tightening pushes the model into empty tool calls or refusals because it cannot pick a value. Go in three stages.
Warn only. Leave the schema untouched; when a value outside the expected set arrives, just log it as schema_candidate_violation. Watch for one or two weeks to see whether false positives show up.
Soft constraint. Spell it out in the description: "always use one of: done / failed." It has no enforcement, but this alone collapses most of the spelling variance. Keep the warn log running here too.
Hard constraint. Once the warnings are quiet enough, add the enum. At the same time, keep one escape-hatch value (say "unknown") for the unexpected, and route it to a default branch in the receiving code.
The tightened tool definition looks like this:
const sendNotification = { name: "send_notification", description: "Send a notification. status must be one of the enum; use unknown if undecidable.", input_schema: { type: "object" as const, properties: { status: { type: "string", enum: ["done", "failed", "unknown"] }, priority: { type: "integer", minimum: 1, maximum: 5 }, channel: { type: "string", enum: ["push", "email"] }, }, required: ["status", "channel"], },};
"完了" disappears here structurally. You do not have to ask the model in the prompt to "write in English." The value outside the set simply cannot be generated.
Before and after
Here are the results of observing the same notification tool for 2,000 calls each, once with the loose schema and once with the hard constraint. "Invalid argument rate" is the share of arguments that fell outside the receiving code's expected set; "retry rate" is the share that triggered an on-the-spot validation retry.
Metric
Loose schema
After enum tightening
Invalid argument rate
6.1%
0.2%
Retry rate
4.3%
0.1%
Tool definition tokens
~180
~120
Empty tool calls
0%
0.05%
The token count going down is easy to miss. Declaring the set with an enum is shorter, and more reliable, than piling long caveats into the description to coax consistent spelling. Keeping an escape-hatch value meant empty tool calls barely moved.
What the docs don't tell you
An enum works twice: as a constraint and as a short instruction. The enumerated values double as a hint to the model, so you can often delete a paragraph of prose caveats. Tightening frequently makes the definition lighter.
Over-tightening turns into refusals and empty calls. Exclude a legitimate value that never appeared in your window and the model is cornered into "cannot choose." Always keep one escape-hatch value and route it to a default branch.
UI and locale-derived values will leak in. Running a Japanese app, display strings like "完了" seep into arguments. Without telemetry, that 6% stays invisible forever.
Distributions shift with model updates. Switch models and the argument habits change with them. Treat tightening as a recurring quarterly review driven by ongoing records, not a one-off.
Recommendations by situation
Situation
Recommendation
Low-traffic, small tool
Telemetry only; tightening isn't worth the effort
High-frequency tool whose branches depend on the value
Hard enum + a mandatory escape-hatch value
Path where user input flows into arguments
Pattern constraint plus a second check on the receiving side
Running several models
Record with the model name and compare distributions per model
A correct type does not protect meaning. Measure the values that arrive, declare the set, and leave one way out. Those three steps catch most of the branches that fall through in silence, right at the entrance.
I hope this helps with your own implementation. Thank you for reading.
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.