{"record":{"id":"eaf3f7bac89dc5a6","repo":"zed-industries/zed","slug":"custom-tool-text-input-cannot-be-used-as-json","errorCode":null,"errorMessage":"custom tool text input cannot be used as JSON","messagePattern":"custom tool text input cannot be used as JSON","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/language_model_core/src/language_model_core.rs","lineNumber":510,"sourceCode":"    };\n    response\n        .get(\"error\")\n        .and_then(|error| error.get(\"code\"))\n        .or_else(|| response.get(\"code\"))\n        .and_then(serde_json::Value::as_str)\n        == Some(\"invalid_encrypted_content\")\n}\n\n#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]\n#[serde(rename_all = \"snake_case\")]\npub enum StopReason {\n    EndTurn,\n    MaxTokens,\n    ToolUse,\n    Refusal,\n}\n\n#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize, Default)]\npub struct TokenUsage {\n    #[serde(default, skip_serializing_if = \"is_default\")]\n    pub input_tokens: u64,\n    #[serde(default, skip_serializing_if = \"is_default\")]\n    pub output_tokens: u64,\n    #[serde(default, skip_serializing_if = \"is_default\")]\n    pub cache_creation_input_tokens: u64,\n    #[serde(default, skip_serializing_if = \"is_default\")]\n    pub cache_read_input_tokens: u64,\n}\n\nimpl TokenUsage {\n    pub fn total_tokens(&self) -> u64 {\n        self.input_tokens\n            + self.output_tokens\n            + self.cache_read_input_tokens\n            + self.cache_creation_input_tokens\n    }","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/zed-industries/zed/blob/5a9b9558db01a6b906cec2fb70a797affdc58cdd/crates/language_model_core/src/language_model_core.rs#L492-L528","documentation":"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.","triggerScenarios":"Thrown at crates/language_model_core/src/language_model_core.rs:479 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Match on the input variant first and treat Text as raw string input (e.g. pass it through unparsed)","Only call into_json() on Json-variant tool inputs (guard with as_json())","Redefine the tool as a JSON-input tool if structured arguments are required"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5a9b9558db01a6b906cec2fb70a797affdc58cdd","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}