{"record":{"id":"df624b483386e90f","repo":"sigoden/aichat","slug":"the-call-call-name-has-invalid-arguments-arg","errorCode":null,"errorMessage":"The call '{call_name}' has invalid arguments: {arguments}","messagePattern":"The call '(.+?)' has invalid arguments: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/function.rs","lineNumber":183,"sourceCode":"    pub fn new(name: String, arguments: Value, id: Option<String>) -> Self {\n        Self {\n            name,\n            arguments,\n            id,\n        }\n    }\n\n    pub fn eval(&self, config: &GlobalConfig) -> Result<Value> {\n        let (call_name, cmd_name, mut cmd_args, envs) = match &config.read().agent {\n            Some(agent) => self.extract_call_config_from_agent(config, agent)?,\n            None => self.extract_call_config_from_config(config)?,\n        };\n\n        let json_data = if self.arguments.is_object() {\n            self.arguments.clone()\n        } else if let Some(arguments) = self.arguments.as_str() {\n            let arguments: Value = serde_json::from_str(arguments).map_err(|_| {\n                anyhow!(\"The call '{call_name}' has invalid arguments: {arguments}\")\n            })?;\n            arguments\n        } else {\n            bail!(\n                \"The call '{call_name}' has invalid arguments: {}\",\n                self.arguments\n            );\n        };\n\n        cmd_args.push(json_data.to_string());\n\n        let output = match run_llm_function(cmd_name, cmd_args, envs)? {\n            Some(contents) => serde_json::from_str(&contents)\n                .ok()\n                .unwrap_or_else(|| json!({\"output\": contents})),\n            None => Value::Null,\n        };\n","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/function.rs#L165-L201","documentation":"During function/tool-call evaluation, the arguments field must be a JSON object or a JSON-encoded string of an object. If it's a string that fails to parse as JSON, or any other JSON type, evaluation aborts with this error naming the call and the offending arguments.","triggerScenarios":"Calling Function::eval where self.arguments is a non-JSON string (e.g. Python-dict-style text with single quotes) or a scalar/array instead of an object.","commonSituations":"LLM emits malformed JSON arguments in a tool call; single-quoted or trailing-comma JSON from the model; arguments serialized as a plain string without JSON encoding.","solutions":["Inspect the raw arguments string and fix the JSON (quotes, trailing commas)","Have the model retry the tool call, or re-prompt with stricter JSON instructions","Pre-validate/sanitize argument strings with serde_json::from_str before eval"],"exampleFix":"// before: arguments = \"{ 'path': '/tmp' }\" (invalid JSON)\n// after: arguments = \"{ \\\"path\\\": \\\"/tmp\\\" }\"","handlingStrategy":"validation","validationCode":"fn valid_args(args: &serde_json::Value) -> bool {\n    args.is_object()\n        || args.as_str().map(|s| serde_json::from_str::<serde_json::Value>(s).map(|v| v.is_object()).unwrap_or(false)).unwrap_or(false)\n}","typeGuard":"fn as_object_args(args: &serde_json::Value) -> Option<serde_json::Value> {\n    match args {\n        v if v.is_object() => Some(v.clone()),\n        serde_json::Value::String(s) => serde_json::from_str(s).ok().filter(|v| v.is_object()),\n        _ => None,\n    }\n}","tryCatchPattern":"match eval_function(&f) {\n    Err(e) if e.to_string().contains(\"has invalid arguments\") => {\n        // re-prompt the model / retry with strict JSON schema\n    }\n    other => other?,\n}","preventionTips":["Use JSON-schema-constrained tool-call arguments from the model","Reject single-quoted JSON early with a pre-parse check","Log raw arguments before eval for post-mortem"],"tags":["json","function-calling","parsing"],"backgroundTag":"json-parse-error","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}