{"record":{"id":"64974ef8147a4bb5","repo":"Hmbown/CodeWhale","slug":"moonshot-function-parameters-failed-safe-compatibi","errorCode":null,"errorMessage":"Moonshot function parameters failed safe compatibility validation: {error}","messagePattern":"Moonshot function parameters failed safe compatibility validation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/client/chat.rs","lineNumber":932,"sourceCode":"    };\n    mirror_minimax_reasoning_details_for_messages(messages);\n}\n\nfn sanitize_moonshot_chat_tools(chat_tools: &mut [Value]) -> Result<()> {\n    for tool in chat_tools {\n        let Some(function) = tool\n            .as_object_mut()\n            .and_then(|tool| tool.get_mut(\"function\"))\n            .and_then(Value::as_object_mut)\n        else {\n            continue;\n        };\n        let Some(parameters) = function.get_mut(\"parameters\") else {\n            continue;\n        };\n        let note = crate::tools::schema_sanitize::sanitize_for_kimi_parameters(parameters)\n            .map_err(|error| {\n                anyhow::anyhow!(\n                    \"Moonshot function parameters failed safe compatibility validation: {error}\"\n                )\n            })?;\n        if let Some(note) = note {\n            let description = function\n                .get(\"description\")\n                .and_then(Value::as_str)\n                .unwrap_or_default();\n            let description = if description.is_empty() {\n                note\n            } else {\n                format!(\"{description} {note}\")\n            };\n            function.insert(\"description\".to_string(), json!(description));\n        }\n    }\n    Ok(())\n}","sourceCodeStart":914,"sourceCodeEnd":950,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/client/chat.rs#L914-L950","documentation":"Before sending tools to Moonshot/Kimi, the client runs `sanitize_for_kimi_parameters`, which enforces MFJS (Moonshot's JSON Schema subset) rules: the parameters root must be a plain `type: \"object\"` schema, internal `$ref`s must resolve and inline, references must terminate, and defaults/ranges must be valid. When the schema cannot be transformed safely, the request is aborted with this error instead of sending a schema Moonshot would reject.","triggerScenarios":"A tool whose `function.parameters` root is not an object schema (e.g. root-level `anyOf`/`allOf` that cannot be flattened); external or cyclic `$ref`s; an MFJS-invalid default or range; schemas exceeding MFJS resource limits.","commonSituations":"Porting tool definitions written for OpenAI's looser schema handling to Moonshot; tools generated from TypeScript types with root unions; large schemas with many nested references.","solutions":["Change the tool's parameters root to a concrete `type: \"object\"` schema","Inline all `$ref`s — MFJS rejects unresolved, external, or cyclic references","Simplify root-level composition (`anyOf`/`allOf`/`oneOf` at the root) into nested properties","If the tool schema is fixed by an upstream dependency, route that tool to a different provider"],"exampleFix":"// before\n{\n  \"name\": \"apply_patch\",\n  \"function\": {\n    \"parameters\": { \"anyOf\": [ { \"type\": \"object\" }, { \"type\": \"string\" } ] }\n  }\n}\n\n// after\n{\n  \"name\": \"apply_patch\",\n  \"function\": {\n    \"parameters\": {\n      \"type\": \"object\",\n      \"properties\": { \"mode\": { \"type\": \"string\", \"enum\": [\"object\", \"raw\"] } }\n    }\n  }\n}","handlingStrategy":"validation","validationCode":"fn is_mfjs_safe_parameters(params: &serde_json::Value) -> bool {\n    let root_is_object = params\n        .get(\"type\")\n        .and_then(|t| t.as_str())\n        .map(|t| t == \"object\")\n        .unwrap_or(false);\n    let no_root_ref = params.get(\"$ref\").is_none();\n    root_is_object && no_root_ref\n}\n\n// Validate the tool catalog before the Moonshot request:\nfor tool in &tools {\n    if !is_mfjs_safe_parameters(&tool[\"function\"][\"parameters\"]) {\n        return Err(anyhow::anyhow!(\"tool {} is not MFJS-compatible; route it elsewhere\", tool[\"function\"][\"name\"]));\n    }\n}","typeGuard":"fn is_mfjs_safe_parameters(params: &serde_json::Value) -> bool {\n    params.get(\"type\").and_then(|t| t.as_str()) == Some(\"object\")\n        && params.get(\"$ref\").is_none()\n}","tryCatchPattern":"match client.send(request).await {\n    Err(e) if e.to_string().contains(\"Moonshot function parameters failed\") => {\n        // Fix the tool schema or route to another provider; retrying unchanged always fails\n        route_tools_to_alternate_provider();\n    }\n    result => result,\n}","preventionTips":["Author tool parameter schemas with a concrete `type: \"object\"` root","Inline `$ref`s; never ship external or cyclic references in tool schemas","Test the tool catalog against Moonshot once at startup, not per request"],"tags":["moonshot","kimi","tools","json-schema","validation"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}