zed-industries/zed · error

custom tool text input cannot be used as JSON

Error message

custom tool text input cannot be used as JSON

What it means

Raised in LanguageModelToolUseInput::into_json: the caller asked to convert the tool input into a serde_json::Value, but the input is the freeform Text variant, which has no JSON representation. Like the parse() error, this is a deterministic type mismatch — the tool use was produced by a text-input (custom/freeform) tool rather than a JSON-schema tool.

Source

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

    };
    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,
}

impl TokenUsage {
    pub fn total_tokens(&self) -> u64 {
        self.input_tokens
            + self.output_tokens
            + self.cache_read_input_tokens
            + self.cache_creation_input_tokens
    }

View on GitHub (pinned to 5a9b9558db)

Solutions

  1. Match on the input variant first and treat Text as raw string input (e.g. pass it through unparsed)
  2. Only call into_json() on Json-variant tool inputs (guard with as_json())
  3. Redefine the tool as a JSON-input tool if structured arguments are required
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/language_model_core/src/language_model_core.rs:479 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/eaf3f7bac89dc5a6. Report an issue: GitHub.