BoundaryML/baml · error · anyhow::Error

BAML Generate failed - Project has errors.

Error message

BAML Generate failed - Project has errors.

What it means

BamlProject.runtime() throws "BAML Generate failed - Project has errors." when neither current_runtime nor last_successful_runtime is available — i.e. the project's BAML has never compiled successfully in this session. Callers (hover, list_functions, list_expr_fns, test-pair listing, generator-version handlers) all depend on a valid runtime, so they fail with this message until the BAML source compiles.

Source

Thrown at engine/language_server/src/baml_project/mod.rs:1225

    //                 file_map.insert(parts[0].to_string(), parts[1].to_string());
    //             }
    //         }
    //         // let diagnostics = self.baml_project.diagnostics(runtime);
    //         // (self.on_success)(diagnostics, file_map);
    //         todo!()
    //     }
    //     Ok(())
    // }
    //

    /// Retrieves a reference to the current runtime or the last successful one.
    pub fn runtime(&self) -> anyhow::Result<&BamlRuntime> {
        if let Some(ref rt) = self.current_runtime {
            Ok(rt)
        } else if let Some(ref rt) = self.last_successful_runtime {
            Ok(rt)
        } else {
            Err(anyhow::anyhow!(
                "BAML Generate failed - Project has errors."
            ))
        }
    }

    /// Returns a map of file URIs to their content.
    pub fn files(&self) -> HashMap<String, String> {
        let files = self.baml_project.files();
        let mut file_map = HashMap::new();
        for file in files {
            let parts: Vec<&str> = file.splitn(2, "BAML_PATH_SPLTTER").collect();
            if parts.len() == 2 {
                file_map.insert(parts[0].to_string(), parts[1].to_string());
            }
        }
        file_map
    }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Fix the BAML compile errors reported in the editor diagnostics / codegen output so runtime() can build a runtime
  2. Run baml-cli generate (or save a .baml file to trigger the LSP rebuild) to produce a successful runtime
  3. Verify baml_src configuration and BAML schema version in generators.baml are valid
  4. Restart the language server after fixing errors to clear the failed state
Defensive patterns

Strategy: validation

Validate before calling

// Guard callers before querying:
if baml_project.runtime().is_err() {
    eprintln!("BAML project has no successful runtime yet; fix compile errors and regenerate.");
    return;
}

Try / catch

match baml_project.runtime() {
    Ok(rt) => use_runtime(rt),
    Err(e) if e.to_string().contains("Project has errors.") => {
        eprintln!("Project never compiled: fix BAML errors and run baml-cli generate.");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Any query hitting the language server (hover, function listing, expression-function listing, function/test-pair listing, get/send_generator_version) while the project contains only a broken runtime: BAML files have compile errors from the start, or the project was opened before any successful generate.

Common situations: Opening an editor on a project with a freshly introduced .baml syntax error; a brand-new project where baml-cli generate was never run successfully; dependency/config (e.g. baml_version or client config) errors preventing the first successful build.

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/02421eaaf918c795. Report an issue: GitHub.