{"record":{"id":"70ab78051ce009d1","repo":"BoundaryML/baml","slug":"function-not-found-while-building-control-flow-visualization","errorCode":null,"errorMessage":"function `{}` not found while building control-flow visualization","messagePattern":"function `(.+?)` not found while building control-flow visualization","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/control_flow.rs","lineNumber":327,"sourceCode":"        }\n    }\n}\n\npub enum HirFunctionRef<'hir> {\n    Expr(&'hir hir::ExprFunction),\n    Llm(&'hir hir::LlmFunction),\n}\n\npub fn build_from_hir(hir: &hir::Hir, function_name: &str) -> Result<ControlFlowVisualization> {\n    if let Some(func) = hir.expr_functions.iter().find(|f| f.name == function_name) {\n        return Ok(build_function_graph(HirFunctionRef::Expr(func)));\n    }\n\n    if let Some(func) = hir.llm_functions.iter().find(|f| f.name == function_name) {\n        return Ok(build_function_graph(HirFunctionRef::Llm(func)));\n    }\n\n    Err(anyhow!(\n        \"function `{}` not found while building control-flow visualization\",\n        function_name\n    ))\n}\n\npub fn build_function_graph(function: HirFunctionRef<'_>) -> ControlFlowVisualization {\n    match function {\n        HirFunctionRef::Expr(func) => build_expr_function_graph(func),\n        HirFunctionRef::Llm(func) => build_llm_function_graph(func),\n    }\n}\n\nfn build_expr_function_graph(func: &hir::ExprFunction) -> ControlFlowVisualization {\n    let mut ctx = HirTraversalContext::new(func.name.as_str(), func.span.clone());\n    ctx.visit_function_body(&func.body);\n    ctx.finish()\n}\n","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/control_flow.rs#L309-L345","documentation":"ControlFlowVisualization::build_from_hir searches the HIR's llm_functions for the requested function name and errors if none matches. This is a lookup failure while constructing a control-flow graph for a function: the name given does not correspond to any LLM function known to the compiler/HIR at that point.","triggerScenarios":"Calling build_from_hir (directly or via function_graph_v2 tooling/tests like builds_simple_expr_function or missing_function_errors) with a function_name that is not present in hir.llm_functions — e.g. a typo, a deleted function, or a name only present as a non-LLM (expr function/test) symbol.","commonSituations":"IDE visualization or tooling referencing a function that was renamed or removed; analyzing a .baml file where the function is declared with different casing; asking for a graph before the HIR finished collecting LLM functions due to earlier compile errors.","solutions":["Verify the function name exactly matches a function declared in the .baml source (check spelling and case).","Ensure the function is an LLM function, not just an expr function, test, or helper — only llm_functions are visualized.","Fix compile errors first so the HIR contains all functions, then retry the visualization.","List available functions from the HIR and pick a valid name before calling build_from_hir."],"exampleFix":"// before\nControlFlowVisualization::build_from_hir(&hir, \"ExtractResume\")?;\n// after\nlet name = \"ExtractResume\";\nif !hir.llm_functions.iter().any(|f| f.name == name) {\n    return Err(anyhow!(\"function `{}` not found in BAML file\", name));\n}\nControlFlowVisualization::build_from_hir(&hir, name)?;","handlingStrategy":"validation","validationCode":"pub fn ensure_function_exists(hir: &IntermediateRepr, name: &str) -> anyhow::Result<()> {\n    if hir.llm_functions.iter().any(|f| f.name == name) {\n        Ok(())\n    } else {\n        Err(anyhow::anyhow!(\n            \"function `{}` not found; available: {:?}\",\n            name,\n            hir.llm_functions.iter().map(|f| f.name.clone()).collect::<Vec<_>>()\n        ))\n    }\n}","typeGuard":"fn has_llm_function(hir: &IntermediateRepr, name: &str) -> bool {\n    hir.llm_functions.iter().any(|f| f.name == name)\n}","tryCatchPattern":"match ControlFlowVisualization::build_from_hir(&hir, fn_name) {\n    Ok(viz) => viz,\n    Err(e) if e.to_string().contains(\"not found while building control-flow\") => {\n        eprintln!(\"Unknown function `{}` — check spelling or recompile\", fn_name);\n        Default::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Source function names for tooling from the HIR/AST itself instead of hardcoding strings.","Resolve names case-sensitively and validate against the compiled BAML file before visualizing.","Fix all compile errors before requesting control-flow graphs so the HIR is complete."],"tags":["rust","hir","visualization","not-found"],"backgroundTag":"function-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}