{"record":{"id":"96a8642fc03faece","repo":"BoundaryML/baml","slug":"toomanyarguments","errorCode":"TooManyArguments","errorMessage":"role() called with two roles: '{a}' and '{b}'","messagePattern":"role\\(\\) called with two roles: '(.+?)' and '(.+?)'","errorType":"exception","errorClass":"minijinja::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jinja-runtime/src/lib.rs","lineNumber":334,"sourceCode":"    for (enum_name, enum_values) in enum_values_by_name {\n        env.add_global(\n            enum_name.clone(),\n            minijinja::value::Value::from_object(MinijinjaBamlEnumType {\n                enum_name,\n                enum_values: enum_values\n                    .into_iter()\n                    .map(|v| (v.value.clone(), v))\n                    .collect(),\n            }),\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() {","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jinja-runtime/src/lib.rs#L316-L352","documentation":"BAML's `role()` template function accepts a role either positionally — `role('assistant')` — or as a keyword — `role(role='assistant')`. Supplying both makes the intent ambiguous, so the function immediately returns a TooManyArguments error naming both conflicting roles.","triggerScenarios":"A chat template calling `{{ role('user', role='system') }}` or a macro that injects a positional role while the template also passes the `role=` kwarg.","commonSituations":"Refactoring templates from positional to keyword style and leaving both; composable partial templates where a wrapper passes role positionally and the inner template adds role=; copy-paste merges of two role call styles.","solutions":["Keep exactly one form: either `{{ role('assistant') }}` or `{{ role(role='assistant') }}`.","If a macro/wrapper supplies the role positionally, remove the literal role= kwarg from the template (or vice versa).","Search the template and any included macros for all role() call sites and unify the style."],"exampleFix":"// before\n{{ _.role('user', role='system') }}Message\n\n// after\n{{ _.role('user') }}Message","handlingStrategy":"validation","validationCode":"// reject role() calls mixing positional and kwarg forms during template linting\nconst bad = /role\\s*\\(\\s*['\"][^'\"]+['\"]\\s*,\\s*role\\s*=/;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one call style project-wide: role('name') OR role(role='name').","Grep templates and macros for all role( call sites in CI.","In wrapper macros, pass the role exactly once."],"tags":["jinja","chat-template","conflicting-arguments","rust"],"backgroundTag":"mutually-exclusive-options","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"}