The 20% of your AI agent's tool schemas that's pure cruft (and the one-liner to strip it)
Source: Dev.to
Your AI agent re-sends every tool’s JSON schema on every single turn. A surprising chunk of that — often ~20% — is non-semantic cruft: tokens that carry zero tool-selection signal, billed on every request. I found this measuring the per-turn token cost of 13 real agents (full study). Here’s where the waste hides, and the one-liner to remove it. When you generate tool schemas from code, the converter quietly adds fields the model doesn’t need: Pydantic adds a “title” to every field via model_json_schema(). zod-to-json-schema appends “$schema” and “additionalProperties” to everything. Pretty-printing alone swings a tool ~20%: the Fetch MCP tool is 236 tokens compact vs 288 pretty-printed — pure whitespace, re-sent every turn. None of it helps the model pick the right tool. On a 20-tool agent that’s easily hundreds of wasted tokens per turn, paid on every message. const strip = (o) => Array.isArray(o) ? o.map(strip) : (o && typeof o === “object”) ? Object.fromEntries(Object.entries(o) .filter(([k]) => ![“$schema”, “additionalProperties”, “title”].includes(k)) .map(([k, v]) => [k, strip(v)])) : o;
// compact, cruft-free — send this to the model const tools_slim = JSON.stringify(strip(tools));
import json
def strip(o): if isinstance(o, list): return [strip(x) for x in o] if isinstance(o, dict): return {k: strip(v) for k, v in o.items() if k not in (“$schema”, “additionalProperties”, “title”)} return o
tools_slim = json.dumps(strip(tools), separators=(”,”, ”:”)) # compact, cruft-free
One caveat: additionalProperties:false is occasionally intentional (strict validation) — drop it from the strip list if you rely on it. Want to see exactly how much your schemas carry (and which tool is worst)? The free Agent Token Profiler flags this cruft automatically and shows the per-turn cost across models — paste your tools, no signup, no key. From AgentLoop, a readable MIT Claude-agent starter. Production token-metering + multi-provider routing live in AgentLoop Pro.