BoundaryML/baml · error

Cannot generate HIR/bytecode due to validation errors

Error message

Cannot generate HIR/bytecode due to validation errors

What it means

This error comes from `baml-cli dump-intermediate` (dump_intermediate.rs). After loading BAML source files, the runtime validates the schema; if the validated schema contains any error-level diagnostics, HIR/bytecode generation is aborted. It is a fail-fast guard so malformed BAML files never reach downstream codegen. The individual validation errors are printed to stderr just before bailing.

Source

Thrown at engine/baml-runtime/src/cli/dump_intermediate.rs:79

        // Read file contents
        let source_files: Vec<SourceFile> = files
            .into_iter()
            .map(|path| {
                let contents = std::fs::read_to_string(&path)?;
                Ok(SourceFile::from((path, contents)))
            })
            .collect::<Result<Vec<_>>>()?;

        // Validate the files
        let validated_schema = validate(&self.from, source_files, feature_flags.clone());

        // Check for validation errors
        if validated_schema.diagnostics.has_errors() {
            eprintln!("Validation errors found:");
            for error in validated_schema.diagnostics.errors() {
                eprintln!("  {error:?}");
            }
            anyhow::bail!("Cannot generate HIR/bytecode due to validation errors");
        }

        // Display warnings if feature flag is set
        if feature_flags.should_display_warnings() && validated_schema.diagnostics.has_warnings() {
            eprintln!(
                "{}",
                validated_schema.diagnostics.warnings_to_pretty_string()
            );
        }

        Ok(validated_schema)
    }

    fn dump_hir(&self, validated_schema: &ValidatedSchema) -> Result<()> {
        // Convert to HIR (filtering is done in to_doc())
        let hir = Hir::from_ast(&validated_schema.db.ast);

        let mut w = Vec::new();

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the validation errors printed above the message (each is printed via eprintln! with debug formatting) and fix each one in your .baml files.
  2. Run `baml-cli fmt` or open the project in VS Code with the BAML extension to get editor diagnostics for the offending files.
  3. Check that the directory you passed actually contains a complete baml_src folder (all referenced .baml files present).
  4. Run the BAML CLI/compiler validate step before dump-intermediate to isolate the failing file.

Example fix

// before (baml_src/resume.baml)
function ExtractResume(text: strng) -> Resume
// after
function ExtractResume(text: string) -> Resume
Defensive patterns

Strategy: validation

Validate before calling

// shell: validate before dumping
baml-cli validate --from baml_src || exit 1
baml-cli dump-intermediate --from baml_src

Try / catch

// parse stderr for the enumerated diagnostics before failing
catch (e) {
  if (String(e.message).includes('Cannot generate HIR/bytecode')) {
    // show earlier stderr lines with per-file validation errors
  }
}

Prevention

When it happens

Trigger: Running the dump-intermediate CLI command (load_and_validate_baml_files -> run) when validated_schema.diagnostics.has_errors() is true, e.g. BAML files with syntax errors, invalid function/llm client definitions, or type errors.

Common situations: Typo in a .baml file, referencing a client or class that doesn't exist, invalid prompt syntax, or a partially-migrated project checked out with inconsistent baml files.

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