{"record":{"id":"a3bc71ab775fd41e","repo":"BoundaryML/baml","slug":"failed-to-parse-function-result","errorCode":null,"errorMessage":"Failed to parse function result: {}","messagePattern":"Failed to parse function result: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/cli/repl.rs","lineNumber":598,"sourceCode":"                            use crate::LLMResponse;\n                            if let LLMResponse::Success(resp) = function_result.llm_response() {\n                                let usage = TokenUsage {\n                                    prompt_tokens: resp.metadata.prompt_tokens,\n                                    output_tokens: resp.metadata.output_tokens,\n                                    total_tokens: resp.metadata.total_tokens,\n                                    cached_input_tokens: resp.metadata.cached_input_tokens,\n                                };\n                                let _ = tx.send(LlmStatusEvent::Finished(run_id, Some(usage)));\n                            } else {\n                                let _ = tx.send(LlmStatusEvent::Finished(run_id, None));\n                            }\n                        }\n                        match function_result.parsed() {\n                            Some(Ok(response_baml_value)) => Ok(response_baml_value\n                                .clone()\n                                .0\n                                .map_meta_owned(|_| (Span::fake(), None))),\n                            Some(Err(e)) => Err(anyhow!(\"Failed to parse function result: {}\", e)),\n                            None => Err(anyhow!(\"No parsed result available from function call\")),\n                        }\n                    }\n                    None => Err(anyhow!(\n                        \"No runtime loaded, it should be impossible to call an LLM function\"\n                    )),\n                }\n            }\n        };\n        // REPL watch handler: collect notifications\n        let watch_notifications = Arc::new(Mutex::new(Vec::new()));\n        let watch_notifications_clone = watch_notifications.clone();\n        let watch_handler = shared_handler(move |notification| {\n            watch_notifications_clone\n                .lock()\n                .unwrap()\n                .push(format!(\"{notification}\"));\n        });","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/cli/repl.rs#L580-L616","documentation":"After an LLM function call completes, the REPL reads the parsed result; if parsing of the raw LLM output against the function's return type failed, the inner parse error is wrapped in this anyhow error. It indicates the model output could not be coerced into the declared BAML return type.","triggerScenarios":"function_result.parsed() returns Some(Err(e)) — the LLM responded but its output failed BAML's parser for the function's return type (e.g. malformed JSON, missing fields).","commonSituations":"Model returns prose instead of JSON, truncated JSON output, output schema drift after editing a function's return type, weak model not following output format instructions.","solutions":["Read the wrapped inner error for the exact parse failure","Tighten the prompt/output-format instructions or switch to a stronger model","Make the return type more permissive (optional fields, string map) if the schema is too strict","Retry the call — LLM output is nondeterministic"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check: ensure the function's return type is parseable and prompt pins the format\n// e.g. verify output_format instructions exist in the BAML function/prompt","typeGuard":null,"tryCatchPattern":"match result { Err(e) if e.to_string().starts_with(\"Failed to parse function result:\") => retry_with_repair_prompt(e), Ok(v) => Ok(v), Err(e) => Err(e) }","preventionTips":["Add explicit output-format instructions to prompts","Keep LLM output JSON small to avoid truncation","Test functions in the BAML playground before REPL use","Prefer models known to follow structured-output instructions"],"tags":["repl","baml","llm-output","parsing"],"backgroundTag":"unexpected-response-shape","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}