{"record":{"id":"fd6313500a551133","repo":"BoundaryML/baml","slug":"no-call-id-found-this-indicates-a-bug-in-baml-please-report","errorCode":null,"errorMessage":"No call_id found. This indicates a bug in BAML. Please report this with a stack trace (RUST_BACKTRACE=1)","messagePattern":"No call_id found\\. This indicates a bug in BAML\\. Please report this with a stack trace \\(RUST_BACKTRACE=1\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/types/context_manager.rs","lineNumber":76,"sourceCode":"    // pub fn call_id(&self) -> Result<uuid::Uuid> {\n    //     self.context\n    //         .lock()\n    //         .unwrap()\n    //         .last()\n    //         .map(|(id, ..)| *id)\n    //         .ok_or_else(|| anyhow::anyhow!(\"No call id found. This indicates a bug in BAML. Please report this with a stack trace (RUST_BACKTRACE=1)\"))\n    // }\n\n    pub fn call_id_stack(&self, allow_empty: bool) -> Result<Vec<FunctionCallId>> {\n        let res: Vec<FunctionCallId> = self\n            .context\n            .lock()\n            .unwrap()\n            .iter()\n            .map(|(.., call_id)| call_id.clone())\n            .collect();\n        if res.is_empty() && !allow_empty {\n            Err(anyhow::anyhow!(\"No call_id found. This indicates a bug in BAML. Please report this with a stack trace (RUST_BACKTRACE=1)\"))\n        } else {\n            Ok(res)\n        }\n    }\n\n    pub fn new(baml_src_reader: BamlSrcReader) -> Self {\n        Self {\n            baml_src_reader: Arc::new(baml_src_reader),\n            context: Default::default(),\n            global_tags: Default::default(),\n        }\n    }\n\n    pub fn upsert_tags(&self, tags: HashMap<String, BamlValue>) {\n        let call_id_stack = {\n            let mut ctx = self.context.lock().unwrap();\n            if let Some((.., last_tags, _)) = ctx.last_mut() {\n                last_tags.extend(tags.clone());","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/types/context_manager.rs#L58-L94","documentation":"RuntimeContextManager::call_id_stack maintains a stack of active function-call IDs; when allow_empty is false and the stack is empty, it returns this anyhow error stating that no call_id was found and calling it a bug in BAML. It is thrown because code (call_function / stream_function_with_expr_events paths) expects to run inside an active function-call context but the context stack was empty.","triggerScenarios":"Calling runtime APIs that resolve the current call_id (e.g. ctx.call_id.get_stack(false) from a client hook, or internal calls from call_function / stream_function_with_expr_events) when no function call is currently executing on that context.","commonSituations":"Accessing ctx.call_id inside an on_create_client / client-side callback or outside b.FunctionCall context; calling the API from a background thread or after the function call completed; Python/TS users reaching into runtime context manager APIs at the wrong lifecycle point.","solutions":["Only access ctx.call_id inside an active BAML function call (e.g. inside b.FunctionCall / ctx-manager-managed call scope).","Pass allow_empty=true (or use the corresponding API) if an empty stack is legitimate for your use case.","Check for calls from background threads/timers that run after the function call has finished; capture the call_id while the call is live instead.","If the error fires during a normal b.Test / b.Call with RUST_BACKTRACE=1, report it to the BAML repo as the message requests — it is meant to indicate an internal bug."],"exampleFix":"// before (outside any call)\nconst ids = ctx.manager.getCallStack(); // throws: no call_id found\n// after (inside a call)\nawait b.Test<MyFn>(/* ... */); // or call within ctx-manager-managed scope, then read ctx.call_id","handlingStrategy":"try-catch","validationCode":"// Only call when inside a managed call:\nconst safeCallStack = (ctx) => {\n  try { return ctx.manager.getCallStack(false); } catch { return []; }\n};","typeGuard":"const hasActiveCall = (ctx) => {\n  try { return ctx.manager.getCallStack(true).length > 0; } catch { return false; }\n};","tryCatchPattern":"try {\n  const ids = ctx.manager.getCallStack(false);\n} catch (e) {\n  if (String(e).includes('No call_id found')) {\n    // not inside an active BAML call — reschedule or use allow_empty=true\n  } else throw e;\n}","preventionTips":["Read ctx.call_id only inside the function-call lifecycle (hooks tied to an active call).","Capture the call_id synchronously while the call is running; never from deferred/background work.","Use allow_empty=true when an empty stack is acceptable in your integration.","Run with RUST_BACKTRACE=1 during development to attribute unexpected occurrences."],"tags":["baml","internal-state","call-context","runtime"],"backgroundTag":"internal-invariant-violation","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"}