{"record":{"id":"d29d24c4cc696579","repo":"BoundaryML/baml","slug":"missingargument","errorCode":"MissingArgument","errorMessage":"role() called without role. Try role('role') or role(role='role').","messagePattern":"role\\(\\) called without role\\. Try role\\('role'\\) or role\\(role='role'\\)\\.","errorType":"exception","errorClass":"minijinja::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jinja-runtime/src/lib.rs","lineNumber":343,"sourceCode":"            }),\n        );\n    }\n\n    let role_fn = minijinja::Value::from_function(\n        |role: Option<String>, kwargs: Kwargs| -> Result<String, minijinja::Error> {\n            let role = match (role, kwargs.get::<String>(\"role\")) {\n                (Some(b), Ok(a)) => {\n                    // If both are present, we should error\n                    return Err(minijinja::Error::new(\n                        ErrorKind::TooManyArguments,\n                        format!(\"role() called with two roles: '{a}' and '{b}'\"),\n                    ));\n                }\n                (Some(role), _) => role,\n                (_, Ok(role)) => role,\n                _ => {\n                    // If neither are present, we should error\n                    return Err(minijinja::Error::new(\n                        ErrorKind::MissingArgument,\n                        \"role() called without role. Try role('role') or role(role='role').\",\n                    ));\n                }\n            };\n\n            let allow_duplicate_role = match kwargs.get::<bool>(\"__baml_allow_dupe_role__\") {\n                Ok(allow_duplicate_role) => allow_duplicate_role,\n                Err(e) => match e.kind() {\n                    ErrorKind::MissingArgument => false,\n                    _ => return Err(e),\n                },\n            };\n\n            let additional_properties = {\n                let mut props = kwargs\n                    .args()\n                    .filter(|&k| k != \"role\")","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jinja-runtime/src/lib.rs#L325-L361","documentation":"The `role()` function requires a role name from either the positional argument or the `role=` keyword. When both are absent (None positional and no/failed kwarg), it throws MissingArgument with a message showing both accepted call forms.","triggerScenarios":"`{{ role() }}` with no arguments; `{{ role(some_undefined_var) }}` where the variable is undefined/None so the positional is None and the kwarg lookup also fails.","commonSituations":"Dynamically building role names where the variable is empty or undefined; forgetting the argument when converting plain text to a chat message; template macros rendering role() with an unset parameter.","solutions":["Pass the role explicitly: `{{ _.role('user') }}` or `{{ _.role(role='assistant') }}`.","If the role is dynamic, ensure the variable is defined and non-null before rendering (e.g. default it in the template: `role(role_name or 'user')`).","Check upstream variable bindings/args so the role value actually reaches the template."],"exampleFix":"// before\n{{ _.role() }}Hello\n\n// after\n{{ _.role('user') }}Hello","handlingStrategy":"validation","validationCode":"// validate role value exists before render\nif (!roleName) throw new Error(\"role() requires a role: role('user') or role(role='user')\");","typeGuard":"function hasRole(args) { return typeof args?.role === \"string\" && args.role.length > 0; }","tryCatchPattern":null,"preventionTips":["Default dynamic roles: role(role_var or 'user').","Ensure variables used as role names are defined in the render args map.","Never emit bare role() in templates."],"tags":["jinja","chat-template","missing-argument","rust"],"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-14T05:17:10.506Z"}