BoundaryML/baml · error · minijinja::Error
MissingArgument
MissingArgument
Error message
role() called without role. Try role('role') or role(role='role'). What it means
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.
Source
Thrown at engine/baml-lib/jinja-runtime/src/lib.rs:343
}),
);
}
let role_fn = minijinja::Value::from_function(
|role: Option<String>, kwargs: Kwargs| -> Result<String, minijinja::Error> {
let role = match (role, kwargs.get::<String>("role")) {
(Some(b), Ok(a)) => {
// If both are present, we should error
return Err(minijinja::Error::new(
ErrorKind::TooManyArguments,
format!("role() called with two roles: '{a}' and '{b}'"),
));
}
(Some(role), _) => role,
(_, Ok(role)) => role,
_ => {
// If neither are present, we should error
return Err(minijinja::Error::new(
ErrorKind::MissingArgument,
"role() called without role. Try role('role') or role(role='role').",
));
}
};
let allow_duplicate_role = match kwargs.get::<bool>("__baml_allow_dupe_role__") {
Ok(allow_duplicate_role) => allow_duplicate_role,
Err(e) => match e.kind() {
ErrorKind::MissingArgument => false,
_ => return Err(e),
},
};
let additional_properties = {
let mut props = kwargs
.args()
.filter(|&k| k != "role")View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before
{{ _.role() }}Hello
// after
{{ _.role('user') }}Hello Defensive patterns
Strategy: validation
Validate before calling
// validate role value exists before render
if (!roleName) throw new Error("role() requires a role: role('user') or role(role='user')"); Type guard
function hasRole(args) { return typeof args?.role === "string" && args.role.length > 0; } Prevention
- 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.
When it happens
Trigger: `{{ 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- TooManyArguments
- colored diagnostics have a source highlighter
- Encountered impossible jinja expression during parsing
- Failed to parse template '{}': {}
- Failed to get template '{}': {}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/d29d24c4cc696579.
Report an issue: GitHub.