{"record":{"id":"a55eb8337fd938a6","repo":"BoundaryML/baml","slug":"cannot-generate-hir-bytecode-due-to-validation-errors","errorCode":null,"errorMessage":"Cannot generate HIR/bytecode due to validation errors","messagePattern":"Cannot generate HIR/bytecode due to validation errors","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/cli/dump_intermediate.rs","lineNumber":79,"sourceCode":"        // Read file contents\n        let source_files: Vec<SourceFile> = files\n            .into_iter()\n            .map(|path| {\n                let contents = std::fs::read_to_string(&path)?;\n                Ok(SourceFile::from((path, contents)))\n            })\n            .collect::<Result<Vec<_>>>()?;\n\n        // Validate the files\n        let validated_schema = validate(&self.from, source_files, feature_flags.clone());\n\n        // Check for validation errors\n        if validated_schema.diagnostics.has_errors() {\n            eprintln!(\"Validation errors found:\");\n            for error in validated_schema.diagnostics.errors() {\n                eprintln!(\"  {error:?}\");\n            }\n            anyhow::bail!(\"Cannot generate HIR/bytecode due to validation errors\");\n        }\n\n        // Display warnings if feature flag is set\n        if feature_flags.should_display_warnings() && validated_schema.diagnostics.has_warnings() {\n            eprintln!(\n                \"{}\",\n                validated_schema.diagnostics.warnings_to_pretty_string()\n            );\n        }\n\n        Ok(validated_schema)\n    }\n\n    fn dump_hir(&self, validated_schema: &ValidatedSchema) -> Result<()> {\n        // Convert to HIR (filtering is done in to_doc())\n        let hir = Hir::from_ast(&validated_schema.db.ast);\n\n        let mut w = Vec::new();","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/cli/dump_intermediate.rs#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the validation errors printed above the message (each is printed via eprintln! with debug formatting) and fix each one in your .baml files.","Run `baml-cli fmt` or open the project in VS Code with the BAML extension to get editor diagnostics for the offending files.","Check that the directory you passed actually contains a complete baml_src folder (all referenced .baml files present).","Run the BAML CLI/compiler validate step before dump-intermediate to isolate the failing file."],"exampleFix":"// before (baml_src/resume.baml)\nfunction ExtractResume(text: strng) -> Resume\n// after\nfunction ExtractResume(text: string) -> Resume","handlingStrategy":"validation","validationCode":"// shell: validate before dumping\nbaml-cli validate --from baml_src || exit 1\nbaml-cli dump-intermediate --from baml_src","typeGuard":null,"tryCatchPattern":"// parse stderr for the enumerated diagnostics before failing\ncatch (e) {\n  if (String(e.message).includes('Cannot generate HIR/bytecode')) {\n    // show earlier stderr lines with per-file validation errors\n  }\n}","preventionTips":["Use the BAML VS Code extension for live validation while editing.","Run validation in CI before any dump/codegen step.","Keep baml_src files committed together to avoid partial states."],"tags":["baml","validation","cli","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}