gitbutlerapp/gitbutler · error

Failed to parse parameters

Error message

Failed to parse parameters: {e}

What it means

After locating the tool, `call_tool_inner` parses the `parameters` JSON string with serde_json::from_str; a malformed JSON string is wrapped in this error. It is a pre-call parameter decoding failure, not a tool execution failure.

Solutions

  1. Validate/repair the parameters string with JSON.parse or serde_json::from_str on the caller side before invoking
  2. Strip markdown fences/prose and re-extract the JSON object from the LLM output
  3. Ensure streamed tool-call arguments are fully accumulated before parsing
  4. Log the raw parameters string to spot the exact syntax problem

Example fix

// before
toolset.call_tool("commit", "{'message': 'hi'}")?; // invalid JSON
// after
toolset.call_tool("commit", r#"{"message": "hi"}"#)?;
Defensive patterns

Strategy: validation

Validate before calling

function safeParams(raw: string): string {
  JSON.parse(raw); // throws before the call if invalid
  return raw;
}
toolset.call_tool(name, safeParams(raw));

Type guard

function isValidJson(s: string): boolean {
  try { JSON.parse(s); return true; } catch { return false; }
}

Try / catch

try {
  toolset.call_tool(name, params_str)
} catch (e) {
  if (String(e).startsWith('Failed to parse parameters')) {
    const repaired = extractJsonObject(params_str);
    return repaired ? toolset.call_tool(name, repaired) : Err(e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a parameters string that is invalid JSON (truncated output from an LLM, unescaped newlines/quotes, trailing commas, or a non-JSON plain string).

Common situations: Model-generated tool arguments arrive with prose or markdown around the JSON; streaming responses cut mid-JSON; hand-written automation passes single-quoted (Python-style) JSON.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/74e7d9f6ce9a76a5. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-tools/src/tool.rs:43

impl<'a> WorkspaceToolset<'a> {
    pub fn new(ctx: &'a mut Context) -> Self {
        WorkspaceToolset {
            ctx,
            tools: BTreeMap::new(),
            commit_mapping: HashMap::new(),
        }
    }

    fn call_tool_inner(
        &mut self,
        name: &str,
        parameters: &str,
    ) -> anyhow::Result<serde_json::Value> {
        let tool = self
            .get(name)
            .ok_or_else(|| anyhow::anyhow!("Tool '{name}' not found"))?;
        let params: serde_json::Value = serde_json::from_str(parameters)
            .map_err(|e| anyhow::anyhow!("Failed to parse parameters: {e}"))?;
        tool.call(params, self.ctx, &mut self.commit_mapping)
    }
}

impl Toolset for WorkspaceToolset<'_> {
    fn register_tool<T: Tool>(&mut self, tool: T) {
        self.tools.insert(tool.name(), Arc::new(tool));
    }

    fn get(&self, name: &str) -> Option<Arc<dyn Tool>> {
        self.tools.get(name).cloned()
    }

    fn list(&self) -> Vec<Arc<dyn Tool>> {
        self.tools.values().cloned().collect()
    }

    fn call_tool(&mut self, name: &str, parameters: &str) -> serde_json::Value {

View on GitHub (pinned to 58e5313667)