{"record":{"id":"15656b5ecd47a237","repo":"BoundaryML/baml","slug":"failed-to-deserialize-response-0","errorCode":null,"errorMessage":"Failed to deserialize response: {0}","messagePattern":"Failed to deserialize response: (.+?)","errorType":"exception","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/tracingv2/publisher/publisher.rs","lineNumber":199,"sourceCode":"        };\n\n        match timeout(timeout_duration, fut).await {\n            Ok(res) => res,\n            Err(_) => Err(ApiError::Timeout(timeout_duration)),\n        }\n    }\n}\n\n#[derive(thiserror::Error, Debug)]\npub enum ApiError {\n    #[error(\"Transport error: {0}\")]\n    Transport(reqwest::Error),\n    #[error(\"HTTP error: {status} {body}\")]\n    Http {\n        status: reqwest::StatusCode,\n        body: String,\n    },\n    #[error(\"Failed to deserialize response: {0}\")]\n    Deserialize(serde_json::Error),\n    #[error(\"Request timed out after {0:?}\")]\n    Timeout(Duration),\n}\n\nimpl TypeLookup for RuntimeAST {\n    fn type_lookup(&self, name: &str) -> Option<Arc<baml_rpc::BamlTypeId>> {\n        self.ast.type_lookup(name)\n    }\n\n    fn function_lookup(&self, name: &str) -> Option<Arc<baml_rpc::ast::tops::BamlFunctionId>> {\n        self.ast.function_lookup(name)\n    }\n\n    fn baml_src_hash(&self) -> Option<String> {\n        self.ast.baml_src_hash()\n    }\n}","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/tracingv2/publisher/publisher.rs#L181-L217","documentation":"This is the Display message of ApiError::Deserialize in the BAML trace publisher. It is thrown when the response from the BAML tracing API could not be deserialized with serde_json — the request succeeded at the HTTP level but the body is not the JSON shape the client expects. Usually indicates an API/client version mismatch or a proxy/error page returning non-JSON.","triggerScenarios":"The collector responds with JSON that does not match the expected response struct (e.g. a check_response for source upload missing fields or changed schema), or a proxy/gateway returns an HTML error page, or an incompatible BAML server version is deployed.","commonSituations":"Self-hosted/older BAML gateway version returning an older response schema, a corporate proxy intercepting with an HTML auth page, or a new BAML client talking to an old backend.","solutions":["Log the raw response body to see what was actually returned.","Upgrade the BAML runtime and the BAML cloud/gateway to matching versions.","Bypass or fix any proxy that rewrites responses (check for HTML error pages).","Report schema mismatch to BAML if versions are current."],"exampleFix":"// before\nlet resp: CheckResponse = serde_json::from_str(&body)?;\n// after\nlet resp: CheckResponse = serde_json::from_str(&body)\n    .map_err(|e| { log::error!(\"unexpected collector body: {body}\"); ApiError::Deserialize(e) })?;","handlingStrategy":"try-catch","validationCode":"// verify server/client compatibility\nbody = requests.get(f\"{BAML_URL}/v1/check\", headers=auth_headers).text\njson.loads(body)  # must not raise; HTML responses indicate a proxy issue","typeGuard":"fn is_deserialize_err(e: &ApiError) -> bool { matches!(e, ApiError::Deserialize(_)) }","tryCatchPattern":"match res {\n    Err(ApiError::Deserialize(e)) => {\n        log::error!(\"collector sent non-JSON/unexpected body: {e}\");\n        // fall back: disable export or queue events for later\n    }\n    Err(e) => log::error!(\"publish failed: {e}\"),\n    Ok(_) => {}\n}","preventionTips":["Keep BAML runtime and cloud/gateway versions in sync","Bypass proxies that rewrite API responses","Log the raw response body on deserialize failures","Pin gateway version when self-hosting"],"tags":["json","serialization","baml","tracing"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}