{"record":{"id":"ead170106ce99b23","repo":"BoundaryML/baml","slug":"enum-name-not-found","errorCode":null,"errorMessage":"Enum {name} not found","messagePattern":"Enum (.+?) not found","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jinja-runtime/src/output_format/types.rs","lineNumber":1068,"sourceCode":"    }\n}\n\n#[cfg(test)]\nimpl OutputFormatContent {\n    pub fn new_array() -> Self {\n        Self::target(TypeIR::List(Box::new(TypeIR::string()), Default::default())).build()\n    }\n\n    pub fn new_string() -> Self {\n        Self::target(TypeIR::string()).build()\n    }\n}\n\nimpl OutputFormatContent {\n    pub fn find_enum(&self, name: &str) -> Result<&Enum> {\n        self.enums\n            .get(name)\n            .ok_or_else(|| anyhow::anyhow!(\"Enum {name} not found\"))\n    }\n\n    pub fn find_class(&self, mode: &baml_types::StreamingMode, name: &str) -> Result<&Class> {\n        self.classes\n            .get(&(name.to_string(), *mode))\n            .ok_or_else(|| anyhow::anyhow!(\"Class {name} not found\"))\n    }\n\n    pub fn find_recursive_alias_target(&self, name: &str) -> Result<&TypeIR> {\n        self.structural_recursive_aliases\n            .get(name)\n            .ok_or_else(|| anyhow::anyhow!(\"Recursive alias {name} not found\"))\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use std::vec;","sourceCodeStart":1050,"sourceCodeEnd":1086,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jinja-runtime/src/output_format/types.rs#L1050-L1086","documentation":"OutputFormatContent::find_enum performs a map lookup of enums by name and converts a miss into an anyhow error. It means the LLM response or jinja code referenced an enum that is not present in the BAML schema's output format. The library throws this when rendering or deserializing output that names an unknown enum.","triggerScenarios":"Calling find_enum(name) when no enum with that name exists in the current OutputFormatContent — e.g. the LLM streamed an enum name not declared in the BAML schema, or the schema was changed/renamed between runs.","commonSituations":"Renaming or deleting an enum in a .baml file while cached/persisted partial responses still reference the old name; typos in enum names inside prompt templates; stale client binaries out of sync with the server-side schema.","solutions":["Check the enum name spelling against the enums declared in your .baml schema.","Regenerate the BAML client (baml-cli generate) after any schema change so generated code matches the schema.","Invalidate any cached or persisted partial LLM responses that reference the old enum name.","Wrap find_enum calls or error-propagated paths in error handling that surfaces the missing enum name to the user."],"exampleFix":"// before: schema no longer declares this enum\nlet e = output_format.find_enum(\"Sentiment\")?;\n// after: add to .baml and regenerate\n// enum Sentiment { POSITIVE NEGATIVE }  ->  baml-cli generate","handlingStrategy":"validation","validationCode":"// rust: before consuming streamed output\nlet known: std::collections::HashSet<&str> = output_format.enums.keys().map(|s| s.as_str()).collect();\nif !known.contains(referenced_enum) {\n    return Err(anyhow::anyhow!(\"schema drift: enum '{}' not in output format\", referenced_enum));\n}","typeGuard":"fn enum_exists(of: &OutputFormatContent, name: &str) -> bool { of.enums.contains_key(name) }","tryCatchPattern":"match output_format.find_enum(name) {\n    Ok(e) => use_enum(e),\n    Err(err) => log::error!(\"enum lookup failed: {err:#}\"),\n}","preventionTips":["Regenerate BAML clients after every schema change","Avoid hardcoding enum names in templates; reference schema symbols","Invalidate cached partial responses on schema version bump"],"tags":["rust","schema","enum","lookup-failed"],"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"}