BoundaryML/baml · error
Failed to parse function result: {}
Error message
Failed to parse function result: {} What it means
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.
Source
Thrown at engine/baml-runtime/src/cli/repl.rs:598
use crate::LLMResponse;
if let LLMResponse::Success(resp) = function_result.llm_response() {
let usage = TokenUsage {
prompt_tokens: resp.metadata.prompt_tokens,
output_tokens: resp.metadata.output_tokens,
total_tokens: resp.metadata.total_tokens,
cached_input_tokens: resp.metadata.cached_input_tokens,
};
let _ = tx.send(LlmStatusEvent::Finished(run_id, Some(usage)));
} else {
let _ = tx.send(LlmStatusEvent::Finished(run_id, None));
}
}
match function_result.parsed() {
Some(Ok(response_baml_value)) => Ok(response_baml_value
.clone()
.0
.map_meta_owned(|_| (Span::fake(), None))),
Some(Err(e)) => Err(anyhow!("Failed to parse function result: {}", e)),
None => Err(anyhow!("No parsed result available from function call")),
}
}
None => Err(anyhow!(
"No runtime loaded, it should be impossible to call an LLM function"
)),
}
}
};
// REPL watch handler: collect notifications
let watch_notifications = Arc::new(Mutex::new(Vec::new()));
let watch_notifications_clone = watch_notifications.clone();
let watch_handler = shared_handler(move |notification| {
watch_notifications_clone
.lock()
.unwrap()
.push(format!("{notification}"));
});View on GitHub (pinned to bd85ce9dee)
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
Defensive patterns
Strategy: retry
Validate before calling
// Pre-check: ensure the function's return type is parseable and prompt pins the format // e.g. verify output_format instructions exist in the BAML function/prompt
Try / catch
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) } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- No parsed result available from function call
- expected `true` or `false`, got `{raw}`
- expected `null`, got `{raw}`
- No JSON objects found
- No markdown blocks found
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/a3bc71ab775fd41e.
Report an issue: GitHub.