Code mode's 10 failure modes: 58% cheaper per Pydantic benchmark, but easier to break
himanshu_942 · reddit · 2026-11-25
A practitioner breaks down 10 failure modes of programmatic tool calling (code mode), where the model writes a script that calls your tools instead of invoking them one at a time. Pydantic's benchmark of 5,276 runs across eight models found code mode cuts cost by 58% and wall time by 51% on long tasks — but it also moves dozens of tool calls into code nobody reviews before execution.
Script-to-tool contract
- Unpredictable return types (model writes result.items[0].email before seeing a response) — fix with typed output schemas and one usage example per tool.
- Silent failures (errors returning [] look like "no results") — return {ok:false, error} and list tool errors in run reports.
- Runtime mismatches (TS annotations in JS, missing await) — state exact language/version/packages and feed parse errors back for retry.
The proxy between script and world
- Unbounded fan-out (a loop over 10k contacts) — per-run call budgets, concurrency/time/memory limits, batch endpoints.
- Non-idempotent writes (crash on email 41, retry resends the first 40) — idempotency keys, separate read/write tools, dry-run, approval for bulk writes.
- Secrets in the sandbox — give the sandbox bindings only; a proxy outside holds credentials with no network egress.
- Prompt injection that runs unreviewed — treat tool output as data; put policy checks at the binding layer (allowed recipients, amount caps).
- No visibility — log every binding call at the proxy and trace under the parent run.
Between runs
- Context flooding from raw stdout — cap output, truncate visibly, aggregate in code.
- Unclear state across runs — pick fresh-or-persistent and say which.
The catch: the proxy is real engineering and carries most of the safety; small jobs (5 items in the benchmark) can cost more with code mode; debugging generated code is harder than reading a clean tool-call trace.
More from coding & agent
- AI agent ARTEX planted malware in 13 Hugging Face repos and leaked its own keys — mawcopolow · 2026-11-25
- PlotJuggler launches browser demos: ANYmal, self-driving, drone datasets open instantly — facontidavide · 2026-11-25
- PlotJuggler 4.2.0 lets Codex and Claude Code control it, 25% faster — facontidavide · 2026-11-25
- Founder rolls out Hermes AI across 5 departments with curated skills per team — Teknium · 2026-11-25
- encoders: Rust crate compiles static embedding models into code for nanosecond-scale CPU embeddings — CatAstro_Piyush · 2026-11-25
- Mid-size company weighs Vicaro vs Agentforce for finance and ops agents beyond Salesforce — Altruistic_Ranger_57 · 2026-11-25