BoundaryML/baml · warning

Operation cancelled: {message}

Error message

Operation cancelled: {message}

What it means

BAML's LLMResponse::Cancelled variant is converted to this error when .content() is called on a cancelled LLM call. The runtime raises it when an orchestration attempt was aborted (e.g. due to a cancellation signal or a faster winning strategy) so the response has no content to return.

Source

Thrown at engine/baml-runtime/src/internal/llm_client/mod.rs:207

            }
            Self::InternalFailure(message) => write!(f, "Failed before LLM call: {message}"),
            Self::Cancelled(message) => write!(f, "Operation cancelled: {message}"),
        }
    }
}

impl LLMResponse {
    pub fn content(&self) -> Result<&str> {
        match self {
            Self::Success(response) => Ok(&response.content),
            Self::LLMFailure(failure) => Err(anyhow::anyhow!("LLM call failed: {failure:?}")),
            Self::UserFailure(message) => Err(anyhow::anyhow!(
                "Failed before LLM call (user error): {message}"
            )),
            Self::InternalFailure(message) => {
                Err(anyhow::anyhow!("Failed before LLM call: {message}"))
            }
            Self::Cancelled(message) => Err(anyhow::anyhow!("Operation cancelled: {message}")),
        }
    }
}

#[derive(Debug, Clone, Serialize, PartialEq)]
pub struct LLMErrorResponse {
    pub client: String,
    pub model: Option<String>,
    pub prompt: RenderedPrompt,
    pub request_options: BamlMap<String, serde_json::Value>,
    #[cfg_attr(target_arch = "wasm32", serde(skip_serializing))]
    pub start_time: web_time::SystemTime,
    pub latency: web_time::Duration,

    // Short error message
    pub message: String,
    pub code: ErrorCode,

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Treat this as an expected cancellation, not a bug: catch it and return/propagate the abort to your caller.
  2. Check for cancellation (request abort signal, tokio cancellation token) before starting or while awaiting BAML calls.
  3. If cancellations are unexpected, audit who is dropping/aborting the futures driving the orchestration.
  4. Use retry/orchestration fallback strategies so an aborted attempt falls back to another client.

Example fix

// before
let content = llm_response.content()?; // Operation cancelled: ...
// after
match llm_response {
    LLMResponse::Cancelled(msg) => Err(MyError::Cancelled(msg)),
    resp => Ok(resp.content()?),
}
Defensive patterns

Strategy: try-catch

Type guard

fn is_cancelled(resp: &LLMResponse) -> bool {
    matches!(resp, LLMResponse::Cancelled(_))
}

Try / catch

match llm_response {
    LLMResponse::Cancelled(msg) => return Err(AppError::ClientCancelled(msg)),
    resp => Ok(resp.content()?),
}

Prevention

When it happens

Trigger: Calling .content() on an LLMResponse::Cancelled produced by the orchestrator's tokio::select! race branch (call.rs) when a cancel_future wins the select, e.g. client cancellation or an orchestration strategy abandoning a pending attempt.

Common situations: Users abort HTTP requests to a BAML-backed service; timeouts cancelling in-flight orchestrations; multi-strategy orchestration where a losing branch is discarded mid-call.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


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