BoundaryML/baml · error
error parsing function result: {e}
Error message
error parsing function result: {e} What it means
The function result did have a parsed slot, but the inner parse operation failed with error e. The runtime wraps that error as 'error parsing function result: {e}', meaning the LLM output could not be coerced into the declared output type.
Source
Thrown at engine/baml-runtime/src/async_vm_runtime.rs:1351
BamlValue::Media(media) => Ok(vm.alloc_media(media.clone())),
}
}
fn try_vm_value_from_function_result(
vm: &mut Vm,
resolved_class_names: &HashMap<String, ObjectIndex>,
resolved_enums_names: &HashMap<String, ObjectIndex>,
result: anyhow::Result<FunctionResult>,
) -> anyhow::Result<baml_vm::Value> {
let fn_result = result.context("failed to get function result")?;
// TODO: Return type of .parsed() sucks.
let baml_value = fn_result
.parsed()
.as_ref()
.ok_or_else(|| anyhow!("no parsed result available from function call"))?
.as_ref()
.map_err(|e| anyhow!("error parsing function result: {e}"))?
.clone()
.0
.value();
try_vm_value_from_baml_value(vm, resolved_class_names, resolved_enums_names, &baml_value)
}
impl crate::runtime_interface::InternalRuntimeInterface for BamlAsyncVmRuntime {
fn features(&self) -> crate::internal::ir_features::IrFeatures {
self.llm_runtime.features()
}
fn diagnostics(&self) -> &internal_baml_core::internal_baml_diagnostics::Diagnostics {
self.llm_runtime.diagnostics()
}
fn orchestration_graph(
&self,View on GitHub (pinned to bd85ce9dee)
Solutions
- Inspect the wrapped inner error e to see which field/shape failed
- Tighten the prompt/schema, or make fields optional/nullable where the model may omit them
- Enable BAML's retry policy or output 'repair' behaviors for malformed JSON
- Increase max output tokens if truncation is the cause
Defensive patterns
Strategy: retry
Type guard
if let Some(parsed) = fn_result.parsed() { if parsed.is_err() { handle_parse_failure(parsed.unwrap_err()); } } Try / catch
Err(e) if e.to_string().starts_with("error parsing function result:") => { /* read inner cause, adjust schema/prompt, retry */ } Prevention
- Enable BAML retry policies for parse failures
- Make optional model-omitted fields nullable
- Increase max output tokens to avoid truncation
- Prefer strict JSON output instructions in prompts
When it happens
Trigger: baml function call where the model's raw response fails jsonish parsing against the output format — invalid JSON, wrong shape, truncated output, or missing required fields.
Common situations: Models returning markdown-fenced or truncated JSON; output type expecting fields the model omitted; very long responses cut off by max token limits.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- expected `true` or `false`, got `{raw}`
- expected `null`, got `{raw}`
- Expected {expected}, got {actual}
- Parse response error: {0}
- Jsonish error: {0}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/5a656bec8731df9e.
Report an issue: GitHub.