pub fn diagnose_args(
tool: &str,
args: &str,
required_modes: &[&[&str]],
example: &str,
) -> Result<Value, String>Expand description
Model-friendly tool-arguments validator.
Why this exists: serde’s “missing field X at line 1 column 793” error
reads to weak models (GLM-5.1, Qwen) as a parser-position complaint and
reliably triggers hallucinated “fixes” like “I should use positional
arguments” — wasting a turn or six on the same tool call. See datalog
atomgr-2d99b47d/2026-05-06_08-43-12.md Turns 64–75 for the failure
mode this replaces.
What it returns instead, on failure:
- the keys the model actually provided
- the keys it’s missing for the closest mode
- a one-line example of a correct call
required_modes is a list of accepted key sets — any one fully matched
passes. Single-mode tools pass &[&[required_keys]]. Multi-mode tools
like edit_file pass one slice per mode; the diagnostic picks the mode
with the fewest missing keys for the hint.
Returns the parsed Value on success so callers can avoid a second
parse pass.