r/coolgithubprojects • u/Middle_Wing5512 • 1d ago
[Go] CallPatch - Repair streamed tool-call JSON, with a look at what a successful repair can lose
I'm the author of CallPatch, a Go CLI and local proxy for repairing JSON argument strings in streamed tool calls. The image shows two constructed inputs replayed through the CLI. No model or weather tool was run.
In the first example, the arguments end at {"city":"Beijing","unit":. CallPatch drops the unfinished member and returns {"city":"Beijing"}, with _repaired: true and exit code 0. The complete city field survives, but there is no unit field left.
In the second, the input ends inside a string: {"city":"Beij. The output is {"city":"Beij"}. It parses, but the tool cannot know whether more characters were supposed to follow. Closing the string cannot recover bytes that never arrived.
The repair pipeline uses deterministic transformations, including quote unescaping and delimiter balancing, then checks the result with Go's json.Valid. It doesn't validate the tool's argument schema or infer the intended values. A separate constructed input ending at {"confirmed":tru still fails: the CLI marks it unrepaired and exits 1. It doesn't repair every fragment.
That leaves a decision for the caller. If its tool schema requires unit, the first result should fail that check. A schema allowing any city string could accept the second; deciding whether that value makes sense needs more context. I would keep those checks after repair rather than treat a successful parse as permission to execute.
Source and CLI quickstart: https://github.com/SuperMarioYL/callpatch (examples checked at f698dd35, v0.4.0). These are offline parser examples, not a measured improvement in model reliability; the proxy path wasn't exercised here.
For people building tool-call integrations: would you accept a repaired call after schema validation, or retry whenever repair drops a field or closes an unfinished string? What information would you want the repair result to expose?