BoundaryML/baml · error · minijinja::Error

TooManyArguments

TooManyArguments

Error message

output_format() may only be called with named arguments

What it means

The BAML `output_format()` Jinja filter accepts only keyword (named) arguments. minijinja's `from_args` splits call arguments into positional args and kwargs; if any positional argument was passed, this error is thrown immediately. It exists to fail fast on a call signature the filter cannot interpret.

Source

Thrown at engine/baml-lib/jinja-runtime/src/output_format/mod.rs:51

        match content {
            Some(content) => write!(f, "{content}"),
            None => Ok(()),
        }
    }
}

// TODO: do this but for a class. Use the display method to render the alias.
impl minijinja::value::Object for OutputFormat {
    fn call(
        self: &std::sync::Arc<Self>,
        _state: &minijinja::State<'_, '_>,
        args: &[minijinja::value::Value],
    ) -> Result<minijinja::value::Value, minijinja::Error> {
        use minijinja::{value::from_args, Error};

        let (args, kwargs): (&[Value], Kwargs) = from_args(args)?;
        if !args.is_empty() {
            return Err(Error::new(
                ErrorKind::TooManyArguments,
                "output_format() may only be called with named arguments".to_string(),
            ));
        }

        let prefix = if kwargs.has("prefix") {
            match kwargs.get::<Option<String>>("prefix") {
                Ok(prefix) => Some(prefix),
                Err(e) => {
                    return Err(Error::new(
                        ErrorKind::SyntaxError,
                        format!("Invalid value for prefix (expected string | null): {e}"),
                    ))
                }
            }
        } else {
            None
        };

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Remove any positional arguments and pass only named arguments, e.g. `output_format(prefix="enum:")`.
  2. If you intended to pipe a value into a filter, use the correct BAML macro (e.g. `ctx.output_format`), not `output_format()`.
  3. Check surrounding template edits/wrappers for an accidentally inserted argument before the named ones.

Example fix

// before
{{ output_format(chat) }}
// after
{{ output_format(prefix="", enum_value_prefix="") }}
Defensive patterns

Strategy: validation

Validate before calling

// Template author check: output_format() is keyword-only.
// Bad:  output_format(value)
// Good: output_format(prefix="...")
function validateOutputFormatCall(args) {
  if (args.filter(a => !a.name).length > 0) throw new Error("output_format() accepts only named arguments");
}

Prevention

When it happens

Trigger: Calling `output_format(someValue)` or `output_format(prefix, ...)` with any positional argument inside a BAML prompt template instead of named kwargs like `output_format(prefix="...")`.

Common situations: Copying a Python-style call habit into a Jinja template; misremembering the filter's signature; wrapping an existing filter call and accidentally passing an extra positional argument; confusion between Jinja filters (which pipe a positional value) and this keyword-only function.

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/c836ee11b3aace45. Report an issue: GitHub.