{"record":{"id":"c836ee11b3aace45","repo":"BoundaryML/baml","slug":"toomanyarguments-output-format-may-only-be-called-with-named","errorCode":"TooManyArguments","errorMessage":"output_format() may only be called with named arguments","messagePattern":"output_format\\(\\) may only be called with named arguments","errorType":"error_code","errorClass":"minijinja::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jinja-runtime/src/output_format/mod.rs","lineNumber":51,"sourceCode":"        match content {\n            Some(content) => write!(f, \"{content}\"),\n            None => Ok(()),\n        }\n    }\n}\n\n// TODO: do this but for a class. Use the display method to render the alias.\nimpl minijinja::value::Object for OutputFormat {\n    fn call(\n        self: &std::sync::Arc<Self>,\n        _state: &minijinja::State<'_, '_>,\n        args: &[minijinja::value::Value],\n    ) -> Result<minijinja::value::Value, minijinja::Error> {\n        use minijinja::{value::from_args, Error};\n\n        let (args, kwargs): (&[Value], Kwargs) = from_args(args)?;\n        if !args.is_empty() {\n            return Err(Error::new(\n                ErrorKind::TooManyArguments,\n                \"output_format() may only be called with named arguments\".to_string(),\n            ));\n        }\n\n        let prefix = if kwargs.has(\"prefix\") {\n            match kwargs.get::<Option<String>>(\"prefix\") {\n                Ok(prefix) => Some(prefix),\n                Err(e) => {\n                    return Err(Error::new(\n                        ErrorKind::SyntaxError,\n                        format!(\"Invalid value for prefix (expected string | null): {e}\"),\n                    ))\n                }\n            }\n        } else {\n            None\n        };","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jinja-runtime/src/output_format/mod.rs#L33-L69","documentation":"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.","triggerScenarios":"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=\"...\")`.","commonSituations":"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.","solutions":["Remove any positional arguments and pass only named arguments, e.g. `output_format(prefix=\"enum:\")`.","If you intended to pipe a value into a filter, use the correct BAML macro (e.g. `ctx.output_format`), not `output_format()`.","Check surrounding template edits/wrappers for an accidentally inserted argument before the named ones."],"exampleFix":"// before\n{{ output_format(chat) }}\n// after\n{{ output_format(prefix=\"\", enum_value_prefix=\"\") }}","handlingStrategy":"validation","validationCode":"// Template author check: output_format() is keyword-only.\n// Bad:  output_format(value)\n// Good: output_format(prefix=\"...\")\nfunction validateOutputFormatCall(args) {\n  if (args.filter(a => !a.name).length > 0) throw new Error(\"output_format() accepts only named arguments\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use `name=value` syntax for every argument to output_format().","Never pipe values into output_format() with `|`; it is not a value-taking filter.","Review BAML docs for the current kwarg list before adding arguments."],"tags":["jinja","baml","argument-validation","template"],"backgroundTag":"missing-required-option","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"}