{"record":{"id":"5c6624086ebbd44e","repo":"BoundaryML/baml","slug":"jsonish-error-0","errorCode":null,"errorMessage":"Jsonish error: {0}","messagePattern":"Jsonish error: (.+?)","errorType":"exception","errorClass":"LlmOpError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/sys_ops/src/sap.rs","lineNumber":61,"sourceCode":"        self.db().resolve_with_meta(self.types.stream_ty().as_ref())\n    }\n}\n\n/// Errors that can occur during LLM operations. Relocated verbatim from\n/// `sys_llm`; only `ParseResponseError`, `JsonishError` and `SapError` are\n/// still constructible now that the SAP parse entry points are the sole users.\n#[derive(Debug, thiserror::Error)]\npub enum LlmOpError {\n    #[error(\"Expected {expected}, got {actual}\")]\n    TypeError {\n        expected: &'static str,\n        actual: String,\n    },\n\n    #[error(\"Parse response error: {0}\")]\n    ParseResponseError(String),\n\n    #[error(\"Jsonish error: {0}\")]\n    JsonishError(::bex_sap::jsonish::JsonishError),\n\n    #[error(\"SAP error: {0}\")]\n    SapError(::bex_sap::deserializer::coercer::ParsingError),\n}\n\nimpl From<LlmOpError> for ::sys_types::VmRustFnError {\n    fn from(e: LlmOpError) -> Self {\n        let baml: ::sys_types::VmBamlError = match e {\n            LlmOpError::TypeError { expected, actual } => {\n                ::sys_types::VmBamlError::InvalidArgument {\n                    message: format!(\"expected {expected}, got {actual}\"),\n                }\n            }\n            LlmOpError::ParseResponseError(e) => ::sys_types::VmBamlError::LlmClient { message: e },\n            LlmOpError::JsonishError(e) => ::sys_types::VmBamlError::LlmClient {\n                message: e.to_string(),\n            },","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/sys_ops/src/sap.rs#L43-L79","documentation":"LlmOpError::JsonishError wraps a bex_sap::jsonish::JsonishError produced while flexibly parsing raw LLM output into a JSON-ish value. It surfaces the underlying jsonish parser's failure through the unified LlmOpError enum.","triggerScenarios":"The jsonish parser invoked from the SAP parse entry points cannot convert the model's raw text (bad JSON syntax, unrepairable partial JSON) into a value, and the error is wrapped as JsonishError.","commonSituations":"Model emits JSON with trailing commas, comments, or markdown fences the repairer can't handle; empty responses; encoding issues.","solutions":["Inspect the wrapped JsonishError message for the exact syntax problem","Adjust the prompt to request strict, valid JSON","Update/extend the jsonish repair heuristics if the format is legitimately supported","Retry the request, since LLM formatting faults are often transient"],"exampleFix":"// before\nmatch jsonish::parse(text) { Err(e) => return Err(LlmOpError::JsonishError(e)), ... }\n// after\nlet text = strip_markdown_fences(text);\nmatch jsonish::parse(text) { ... }","handlingStrategy":"retry","validationCode":"if raw.trim().is_empty() { return Err(\"empty response before jsonish parse\".into()); }","typeGuard":"fn looks_like_json(s: &str) -> bool { let t = s.trim(); (t.starts_with('{') && t.ends_with('}')) || (t.starts_with('[') && t.ends_with(']')) }","tryCatchPattern":"match result {\n    Err(LlmOpError::JsonishError(e)) => { log::warn!(\"jsonish: {e}\"); strip_fences_and_retry(raw) }\n    other => other,\n}","preventionTips":["Instruct the model to emit bare JSON without markdown fences","Preprocess responses to strip fences/prose before parsing","Retry generation when repair fails"],"tags":["llm","json","parsing"],"backgroundTag":"json-parse-error","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"}