Hmbown/CodeWhale · error
Moonshot function parameters failed safe compatibility valid
Error message
Moonshot function parameters failed safe compatibility validation: {error} What it means
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.
Source
Thrown at crates/tui/src/client/chat.rs:932
};
mirror_minimax_reasoning_details_for_messages(messages);
}
fn sanitize_moonshot_chat_tools(chat_tools: &mut [Value]) -> Result<()> {
for tool in chat_tools {
let Some(function) = tool
.as_object_mut()
.and_then(|tool| tool.get_mut("function"))
.and_then(Value::as_object_mut)
else {
continue;
};
let Some(parameters) = function.get_mut("parameters") else {
continue;
};
let note = crate::tools::schema_sanitize::sanitize_for_kimi_parameters(parameters)
.map_err(|error| {
anyhow::anyhow!(
"Moonshot function parameters failed safe compatibility validation: {error}"
)
})?;
if let Some(note) = note {
let description = function
.get("description")
.and_then(Value::as_str)
.unwrap_or_default();
let description = if description.is_empty() {
note
} else {
format!("{description} {note}")
};
function.insert("description".to_string(), json!(description));
}
}
Ok(())
}View on GitHub (pinned to 8880682c63)
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
Example fix
// before
{
"name": "apply_patch",
"function": {
"parameters": { "anyOf": [ { "type": "object" }, { "type": "string" } ] }
}
}
// after
{
"name": "apply_patch",
"function": {
"parameters": {
"type": "object",
"properties": { "mode": { "type": "string", "enum": ["object", "raw"] } }
}
}
} Defensive patterns
Strategy: validation
Validate before calling
fn is_mfjs_safe_parameters(params: &serde_json::Value) -> bool {
let root_is_object = params
.get("type")
.and_then(|t| t.as_str())
.map(|t| t == "object")
.unwrap_or(false);
let no_root_ref = params.get("$ref").is_none();
root_is_object && no_root_ref
}
// Validate the tool catalog before the Moonshot request:
for tool in &tools {
if !is_mfjs_safe_parameters(&tool["function"]["parameters"]) {
return Err(anyhow::anyhow!("tool {} is not MFJS-compatible; route it elsewhere", tool["function"]["name"]));
}
} Type guard
fn is_mfjs_safe_parameters(params: &serde_json::Value) -> bool {
params.get("type").and_then(|t| t.as_str()) == Some("object")
&& params.get("$ref").is_none()
} Try / catch
match client.send(request).await {
Err(e) if e.to_string().contains("Moonshot function parameters failed") => {
// Fix the tool schema or route to another provider; retrying unchanged always fails
route_tools_to_alternate_provider();
}
result => result,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- disabled_tools must use Codewhale catalog identifiers: ${",
- Kimi CLI credential import is unsupported. Codewhale does no
- Kimi Code membership-plan API key not found. Get a plan key:
- Moonshot/Kimi API key not found. Get a key: {}. Run 'codewha
- Invalid MCP tool name: {prefixed_name}
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/64974ef8147a4bb5.
Report an issue: GitHub.