Repository navigation
Commit a327f8b
committed
fix(tool): coerce object args to string in edit and write tools
Some models (Qwen3-Coder, GLM4.7, and others) occasionally emit a JSON
object rather than a plain string for tool parameters that expect strings
— e.g. oldString / newString in the edit tool or content in the write
tool. Zod rejects these outright, producing a hard validation error that
causes the model to loop.
Add a z.preprocess step on each affected parameter that serialises any
incoming object value (via JSON.stringify) so it becomes a valid string
before zod validates it. Plain string inputs are unchanged.
Also reorder write tool parameters so filePath comes before content,
matching the edit, read, and apply_patch tools. Small/quantised models
are sensitive to property order in JSON schemas and more reliably emit
filePath when it appears first.
Fixes anomalyco#69181 parent bd53b65 commit a327f8b
2 files changed
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
43 | 53 | | |
44 | 54 | | |
45 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
0 commit comments