{"record":{"id":"46d5f9ce4a58ee80","repo":"BoundaryML/baml","slug":"class-does-not-exist","errorCode":null,"errorMessage":"Class {} does not exist","messagePattern":"Class (.+?) does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jsonish/src/helpers/mod.rs","lineNumber":76,"sourceCode":"        streaming_mode == baml_types::StreamingMode::Streaming,\n    )?;\n\n    Ok(OutputFormatContent::target(output.clone())\n        .enums(enums)\n        .classes(classes)\n        .recursive_classes(recursive_classes)\n        .structural_recursive_aliases(structural_recursive_aliases)\n        .build())\n}\n\nfn find_existing_class_field(\n    class_name: &str,\n    field_name: &str,\n    class_walker: &Result<ClassWalker<'_>>,\n    env_values: &EvaluationContext<'_>,\n) -> Result<(Name, TypeIR, Option<String>, bool)> {\n    let Ok(class_walker) = class_walker else {\n        anyhow::bail!(\"Class {} does not exist\", class_name);\n    };\n\n    let Some(field_walker) = class_walker.find_field(field_name) else {\n        anyhow::bail!(\"Class {} does not have a field: {}\", class_name, field_name);\n    };\n\n    let name = Name::new_with_alias(field_name.to_string(), field_walker.alias(env_values)?);\n    let desc = field_walker.description(env_values)?;\n    let r#type = field_walker.r#type();\n    let streaming_needed = field_walker.item.attributes.streaming_behavior().needed;\n    Ok((name, r#type.clone(), desc, streaming_needed))\n}\n\nfn find_enum_value(\n    enum_name: &str,\n    value_name: &str,\n    enum_walker: &Result<EnumWalker<'_>>,\n    env_values: &EvaluationContext<'_>,","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jsonish/src/helpers/mod.rs#L58-L94","documentation":"find_existing_class_field receives a ClassWalker wrapped in a Result; if the walker itself is an Err (the class could not be resolved in the codebase), it bails with 'Class {} does not exist'. This is used when resolving fields referenced from jinja helpers/templates against the BAML data model.","triggerScenarios":"relevant_data_models calls find_existing_class_field with class_walker = env.find_class/class_walker(name) that returned Err — i.e. the class name in a template helper (e.g. a field-description lookup) has no matching class in the BAML sources.","commonSituations":"Typos in class names inside jinja templates (e.g. ctx.output_format / description helpers); classes deleted or renamed while templates still reference them; multi-file BAML projects where the class lives in a file not loaded.","solutions":["Fix the class name in the template/helper call to match a class declared in your .baml files.","Search your project for the class definition and confirm it is in a loaded .baml file.","Regenerate clients/templates after renames so references stay in sync.","Pre-validate referenced class names in CI (e.g. run baml-cli to surface unresolvable references)."],"exampleFix":"// before: template references wrong class\n{{ ctx.classes[\"UsrInfo\"].name }}\n// after\n{{ ctx.classes[\"UserInfo\"].name }}","handlingStrategy":"validation","validationCode":"// before invoking template helpers that resolve classes\nlet class_walker = env.find_class(class_name);\nif class_walker.is_err() {\n    return Err(anyhow::anyhow!(\"template references unknown class '{}' — check .baml files\", class_name));\n}","typeGuard":"fn class_resolves(env: &FunctionCfg, name: &str) -> bool { env.find_class(name).is_ok() }","tryCatchPattern":"match find_existing_class_field(class_name, field_name, &class_walker, &env) {\n    Ok(v) => use_field(v),\n    Err(err) => return Err(err.context(\"template references a class not defined in .baml\")),\n}","preventionTips":["Reference classes in templates only by names that exist in loaded .baml files","Run baml-cli validation in CI to catch unresolvable references","Grep templates after class renames"],"tags":["rust","schema","class","template"],"backgroundTag":"class-not-found","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"}