{"record":{"id":"13e160331c15276e","repo":"BoundaryML/baml","slug":"parse-error-message","errorCode":null,"errorMessage":"parse error: {message}","messagePattern":"parse error: (.+?)","errorType":"exception","errorClass":"VmBamlError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm_types/src/errors.rs","lineNumber":116,"sourceCode":"    /// `class_name` / `language` are populated when the violation arose from\n    /// a host throw (echoing the offending host exception's identity) and\n    /// `None` when it arose from a wrong-type return (no exception class to\n    /// echo).\n    #[error(\"host contract violation: {message} [class={class_name:?}, lang={language:?}]\")]\n    HostContractViolation {\n        message: String,\n        class_name: Option<String>,\n        language: Option<String>,\n    },\n}\n\n/// An error value from the BAML standard library. Maps 1:1 to a `baml.errors.*` class.\n#[derive(Debug, Error, PartialEq, Clone)]\npub enum VmBamlError {\n    #[error(\"invalid argument: {message}\")]\n    InvalidArgument { message: String },\n\n    #[error(\"parse error: {message}\")]\n    ParseError { message: String },\n\n    #[error(\"I/O error: {message}\")]\n    Io { message: String },\n\n    #[error(\"timeout: {message}\")]\n    Timeout {\n        message: String,\n        duration_ms: Option<i64>,\n    },\n\n    #[error(\"unsupported: {message}\")]\n    Unsupported { message: String },\n\n    #[error(\"access error: {message}\")]\n    AccessError { message: String },\n\n    #[error(\"render prompt: {message}\")]","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm_types/src/errors.rs#L98-L134","documentation":"An error value from the BAML standard library, mapping to the `baml.errors.ParseError` class. It is raised when a stdlib parsing function cannot interpret its input — the input is well-formed as a value of the right type but does not conform to the expected grammar.","triggerScenarios":"Calling stdlib parsers (e.g. JSON parse, datetime parse, number parse) with a string that does not match the expected syntax; the message details where/why parsing failed.","commonSituations":"Feeding LLM-generated text (often slightly malformed JSON) into parsers; user-supplied dates or numbers with unexpected formats; log/config formats that changed between versions.","solutions":["Inspect the `message` for the parse failure position/reason and fix the input or its format.","Validate/normalize input (strip whitespace/code fences) before parsing; for LLM output use a robust extraction step.","Catch `baml.errors.ParseError` and provide a fallback parse path or a retry with a stricter prompt.","Check version-specific format expectations (e.g. date formats) and use explicit format arguments when supported."],"exampleFix":"// before\nlet v = json.parse(response.text); // text may be \"```json\\n{...}\\n```\"\n// after\nlet v = json.parse(strip_code_fence(response.text));\n","handlingStrategy":"try-catch","validationCode":"// BAML: quick sanity check before parsing\nif !trimmed.startsWith(\"{\") {\n  return err(\"not a JSON object\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  let v = json.parse(text);\n} catch e: baml.errors.ParseError {\n  return try_lax_parse(text) ?? report_parse_failure(e.message);\n}","preventionTips":["Strip code fences/whitespace from LLM output before parsing.","Use explicit format strings when parsing dates or numbers.","Ask LLMs for strict JSON-only output and validate before parsing.","Log the raw input alongside the parse error to speed debugging."],"tags":["parse","stdlib","format","baml"],"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"}