{"record":{"id":"bb8bb70d53e87df9","repo":"BoundaryML/baml","slug":"arity-mismatch-expected-args-got","errorCode":null,"errorMessage":"arity mismatch: expected {} args, got {}","messagePattern":"arity mismatch: expected (.+?) args, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":1880,"sourceCode":"                                    thir,\n                                    run_llm_function,\n                                    watch_handler,\n                                    function_name,\n                                )\n                                .await?,\n                            )?);\n                        }\n\n                        // Handle builtin functions\n                        let result =\n                            evaluate_builtin_function(&fn_name, &arg_vals, type_args, &meta)\n                                .await?;\n                        return Ok(EvalValue::Value(result));\n                    }\n                }\n\n                if arity != args.len() {\n                    bail!(\n                        \"arity mismatch: expected {} args, got {}\",\n                        arity,\n                        args.len()\n                    );\n                }\n\n                // Evaluate arguments first\n                let mut arg_vals: Vec<BamlValueWithMeta<ExprMetadata>> =\n                    Vec::with_capacity(args.len());\n                for a in args.iter() {\n                    arg_vals.push(expect_value(\n                        evaluate_expr(\n                            a,\n                            scopes,\n                            thir,\n                            run_llm_function,\n                            watch_handler,\n                            function_name,","sourceCodeStart":1862,"sourceCodeEnd":1898,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L1862-L1898","documentation":"The interpreter compares the resolved callee's declared arity with the number of arguments supplied at the call site and throws \"arity mismatch: expected {} args, got {}\" when they differ. BAML functions have fixed parameter counts enforced at interpretation time.","triggerScenarios":"Calling a BAML function with more or fewer positional arguments than its signature declares, during evaluate_expr_with_context call handling.","commonSituations":"Adding a parameter to a function but not updating all call sites; copy-pasting a call from an older version of a function signature; calling generated/__LLM_FUNCTION__ functions with the wrong argument count.","solutions":["Read the expected count from the message and adjust the call site to pass exactly that many arguments","Check the function's signature for recently added/removed parameters and update all callers","For optional parameters, pass explicit defaults rather than omitting them","If the function is generated, regenerate/refresh definitions so signatures match"],"exampleFix":"// before\nfn add(a, b) { a + b }\nadd(1) // arity mismatch: expected 2 args, got 1\n// after\nadd(1, 2)","handlingStrategy":"validation","validationCode":"// Validate argument count against the function signature before invoking\nfunction checkArity(signatureParams: number, args: unknown[]): void {\n  if (args.length !== signatureParams)\n    throw new Error(`Call needs ${signatureParams} args, got ${args.length}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return fn(...args);\n} catch (e) {\n  if (String(e).startsWith(\"arity mismatch\")) {\n    console.error(String(e), \"— update this call site to match the function signature\");\n  }\n  throw e;\n}","preventionTips":["Update all call sites whenever a function signature changes (use project-wide search)","Use the LSP's find-references to locate callers of changed functions","Prefer explicit parameters over growing positional argument lists","Run type checking / tests on .baml files in CI before deploying"],"tags":["interpreter","arity","function-call"],"backgroundTag":"missing-required-argument","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"}