agentleFS
ryanilanoryanilano/ilano-skills/skills/tool-call-repair/SKILL.md

tool-call-repair

Skill0 starsChanged 50 days agoMITView on GitHub

Validate-then-repair for malformed LLM tool-call inputs, so a recoverable mistake is fixed at the failing path instead of failing the call. Use when an open or cheaper model (DeepSeek, Qwen, GLM, Kimi, local) keeps bouncing off a strict tool schema: null for an optional field, a stringified array, a bare string for an array, an empty {} placeholder, a markdown-autolinked path.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not fail a tool call on recoverable noise.

    line 8
  2. Distinctive:

    No Command Code proprietary source is used or included.

    line 70

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

tool-call-repair

Do not fail a tool call on recoverable noise. Validate first; repair only where the schema actually disagreed.

python3 scripts/tool_call_repair.py '<schema-json>' '<data-json>'

Or import it:

from tool_call_repair import repair_tool_input, fill_relational_defaults

out = repair_tool_input(tool_schema, model_supplied_args, tool_name="readFile", model="deepseek-v4-flash")
if out["status"] == "invalid":
    return out["message"]      # model-readable, no "Error:" prefix
run_tool(out["data"])          # valid or repaired input

Why

A strict schema filters out noise, but it also filters out recoverable noise from any model that did not memorize your exact JSON contract. Big commercial models absorb that cost invisibly; open and cheap models pay it loudly and get called "bad at tool calls." It's usually a harness problem, not a model problem. Ahmad Awais showed DeepSeek V4 Pro beat a frontier model 6/10 on internal evals once a repair layer handled its quirks.

The catalog (finite, compositional, ordered)

RepairModel sentSchema wanted
null-for-optional{"timeoutMs": null}key omitted
json-array-parse"[\"a\",\"b\"]"["a","b"]
empty-placeholder{} (array field)[]
bare-string-wrap"foo"["foo"]
path-autolink"/p/[notes.md](http://notes.md)""/p/notes.md"

Order matters: json-array-parse runs before bare-string-wrap, or '["a","b"]' becomes ['["a","b"]'] — schema-valid, meaning lost.

Rules

  1. Valid inputs are never touched. Parse as-is; only on failure walk the issue list and repair at the failing paths. Preprocessing-before-validation corrupts valid data that merely looks broken (e.g. file content that is itself JSON-shaped).
  2. Mark path fields with "format": "path" in the schema (the pathString() equivalent) so the degenerate markdown-auto-link leak is caught. Real links like [click](https://x.com) pass through untouched.
  3. Relational invariants are not input repair. For a mutually-dependent pair like read_file's offset/limit, use fill_relational_defaults: fill the intended default and surface the choice with NO Error: prefix, so the model self-corrects next turn.
  4. Telemetry is free. The log field (tool_input_repaired:<tool> / tool_input_invalid:<tool>) lets you watch repair rates per (model, tool) and catch a regression before users do.

Attribution

Technique and catalog by Ahmad Awais (@MrAhmadAwais), published in the Command Code "Tool Call Repairs" write-up: https://commandcode.ai/docs/harness-engineering/tool-call-repairs This skill is an independent Python reimplementation of the documented method. No Command Code proprietary source is used or included.

Requirements

python3, standard library only. scripts/test_tool_call_repair.py runs offline in under a second.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.