BoundaryML/baml · error · ExposedError

ExposedError (formatted via format_last_error_with_details)

Error message

ExposedError (formatted via format_last_error_with_details)

What it means

result_with_constraints_content re-wraps a stored error from the parsed result (result_with_constraints) using format_last_error_with_details, which renders the ExposedError with full diagnostic details. It surfaces whatever error the constrained parse produced, enriched with the last-attempt context.

Solutions

  1. Inspect the detailed message from format_last_error_with_details to see the underlying parse/constraint failure.
  2. Fix the prompt/schema so the model output matches the expected BAML type, or relax failing checks.
  3. Catch this error at the call site and fall back to a retry with adjusted prompt or a different client.

Example fix

// before
let value = chain.content().unwrap();

// after
match chain.result_with_constraints_content() {
    Ok(v) => println!("{}", v),
    Err(e) => eprintln!("BAML detailed error: {e:#}"),
}
Defensive patterns

Strategy: try-catch

Try / catch

match chain.result_with_constraints_content() {
    Ok(v) => handle(v),
    Err(e) => log::error!("BAML detailed error: {e:#}"),
}

Prevention

When it happens

Trigger: Calling .content()/result_with_constraints_content() on a ResponseChain whose result_with_constraints is Err — i.e. the LLM output failed constraint checks or parsing during the run.

Common situations: Schema parse failures (output didn't match the BAML return type), failed check()/assert() constraints in the prompt, or client-level errors recorded into the result slot.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/0749a156de037923. Report an issue: GitHub.

Appendix: source

Thrown at engine/baml-runtime/src/types/response.rs:121

            Some((_, _, result)) => result,
            None => &None,
        }
    }

    pub fn result_with_constraints(&self) -> &Option<Result<ResponseBamlValue>> {
        match self.event_chain.last() {
            Some((_, _, result)) => result,
            None => &None,
        }
    }

    pub fn result_with_constraints_content(&self) -> Result<&ResponseBamlValue> {
        let Some(result) = self
            .result_with_constraints()
            .as_ref()
            .map(|res| match res {
                Ok(val) => Ok(val),
                Err(err) => Err(anyhow::anyhow!(self.format_last_error_with_details(err))),
            })
        else {
            // If we don't have a parsed result, check if we have an LLMFailure
            return match self.llm_response() {
                    LLMResponse::LLMFailure(err) => {
                        // Convert LLMFailure to appropriate error type
                        match &err.code {
                            crate::internal::llm_client::ErrorCode::Timeout => {
                                Err(anyhow::anyhow!(crate::errors::ExposedError::TimeoutError {
                                    client_name: err.client.clone(),
                                    message: err.message.clone(),
                                }))
                            }
                            crate::internal::llm_client::ErrorCode::Other(2) => {
                                Err(anyhow::anyhow!(err.message.clone()))
                            }
                            _ => Err(anyhow::anyhow!(
                                crate::errors::ExposedError::ClientHttpError {

View on GitHub (pinned to bd85ce9dee)