zed-industries/zed · error

custom tool text input cannot be parsed as JSON

Error message

custom tool text input cannot be parsed as JSON

What it means

Raised in LanguageModelToolUseInput::parse: the tool use arrived with freeform Text input rather than structured JSON, and the caller asked for a typed deserialization of it. Text inputs (e.g. from custom/freeform tools) can never satisfy a Deserialize bound, so this is a deterministic type mismatch — the caller used parse() on a tool whose input mode is text.

Source

Thrown at crates/language_model_core/src/language_model_core.rs:503

            .min(MAXIMUM_BACKOFF),
    )
}

fn is_invalid_encrypted_content_message(message: &str) -> bool {
    let Ok(response) = serde_json::from_str::<serde_json::Value>(message) else {
        return false;
    };
    response
        .get("error")
        .and_then(|error| error.get("code"))
        .or_else(|| response.get("code"))
        .and_then(serde_json::Value::as_str)
        == Some("invalid_encrypted_content")
}

#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StopReason {
    EndTurn,
    MaxTokens,
    ToolUse,
    Refusal,
}

#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, Default)]
pub struct TokenUsage {
    #[serde(default, skip_serializing_if = "is_default")]
    pub input_tokens: u64,
    #[serde(default, skip_serializing_if = "is_default")]
    pub output_tokens: u64,
    #[serde(default, skip_serializing_if = "is_default")]
    pub cache_creation_input_tokens: u64,
    #[serde(default, skip_serializing_if = "is_default")]
    pub cache_read_input_tokens: u64,
}

View on GitHub (pinned to 5a9b9558db)

Solutions

  1. Check the input kind with as_json()/into_json() before calling parse and handle the Text variant separately
  2. Only call parse::<T>() for tools declared with JSON input schemas
  3. If the tool should emit JSON, fix the tool definition or prompt so the model produces structured input
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/language_model_core/src/language_model_core.rs:472 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20). Data as JSON: /api/errors/bc4d2fd9ca494986. Report an issue: GitHub.