{"record":{"id":"1d23a0839c2f1485","repo":"BoundaryML/baml","slug":"template-string-expects-arguments-but-were-provided","errorCode":null,"errorMessage":"Template string '{}' expects {} arguments, but {} were provided","messagePattern":"Template string '(.+?)' expects (.+?) arguments, but (.+?) were provided","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":2041,"sourceCode":"            item_type(&ir, &TypeIR::recursive_type_alias(\"JsonValue\")).expect(\"should be Some\");\n        let mut expected = TypeIR::recursive_type_alias(\"JsonValue\");\n        expected.meta_mut().streaming_behavior.needed = true;\n        assert_eq!(ret, expected, \"{ret} != {expected}\");\n    }\n}\n\n/// Implementation of TemplateStringRenderer for IntermediateRepr.\n/// This allows template_string calls to be resolved during test argument evaluation.\nimpl TemplateStringRenderer for IntermediateRepr {\n    fn render_template(&self, name: &str, args: &[serde_json::Value]) -> Result<String> {\n        // Find the template string definition\n        let template = self.find_template_string(name)?;\n        let template_content = template.template();\n        let template_params = template.inputs();\n\n        // Validate argument count\n        if args.len() != template_params.len() {\n            anyhow::bail!(\n                \"Template string '{}' expects {} arguments, but {} were provided\",\n                name,\n                template_params.len(),\n                args.len()\n            );\n        }\n\n        // Build the arguments map for minijinja\n        let mut args_map = serde_json::Map::new();\n        for (param, arg) in template_params.iter().zip(args.iter()) {\n            args_map.insert(param.name.clone(), arg.clone());\n        }\n\n        // Collect all template_strings as Jinja macro definitions, then chain\n        // the target template at the end. This matches how the prompt renderer\n        // in jinja-runtime injects macros.\n        let full_template = self\n            .walk_template_strings()","sourceCodeStart":2023,"sourceCodeEnd":2059,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L2023-L2059","documentation":"When rendering a BAML template_string at runtime, `render_template` compares the number of supplied arguments with the template's declared inputs. Any mismatch (too few or too many) bails with this error naming the template, the expected count, and the actual count.","triggerScenarios":"Calling TemplateStringRenderer::render_template(name, args) (used for template_string calls during test argument evaluation) with args.len() != number of inputs declared on the `template_string Name(a, b, ...)` in .baml.","commonSituations":"Adding a parameter to a template_string without updating call sites; passing a single object of args where positional values are expected; generated test code referencing an older template signature.","solutions":["Pass exactly as many arguments as the template_string declares, in declaration order","Update stale call sites after changing the template_string signature in .baml","Compare the counts in the error message (expects N, provided M) to find what to add or remove","If parameters became optional, still pass all declared inputs (pass null) since this renderer requires exact arity"],"exampleFix":"// before (.baml)\ntemplate_string Greet(name: string) #\"Hello {{name}}\"#\n// render_template(\"Greet\", [])  // 0 of 1 args\n\n// after (caller)\nrender_template(\"Greet\", [json!(\"alice\")])","handlingStrategy":"validation","validationCode":"function assertTemplateArity(templateInputs: number, args: unknown[]): void {\n  if (args.length !== templateInputs) {\n    throw new Error(`Template expects ${templateInputs} arguments, got ${args.length}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const out = render_template(name, args);\n} catch (e) {\n  if (String(e).includes('expects') && String(e).includes('arguments')) {\n    console.error('Align call-site args with the template_string inputs in .baml');\n  }\n  throw e;\n}","preventionTips":["Update all template_string call sites when changing its input list","Pass null for unused-but-declared inputs; this renderer requires exact arity","Centralize template invocations in one helper that checks arity","Keep generated test code in sync with template signatures"],"tags":["rust","baml","template-string","arguments"],"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-14T11:17:12.474Z"}