{"record":{"id":"79e9de7756c798d1","repo":"BoundaryML/baml","slug":"syntaxerror","errorCode":"SyntaxError","errorMessage":"Invalid value for prefix (expected string | null): {e}","messagePattern":"Invalid value for prefix \\(expected string \\| null\\): (.+?)","errorType":"error_code","errorClass":"minijinja::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jinja-runtime/src/output_format/mod.rs","lineNumber":61,"sourceCode":"        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        };\n\n        let or_splitter = if kwargs.has(\"or_splitter\") {\n            match kwargs.get::<String>(\"or_splitter\") {\n                Ok(prefix) => Some(prefix),\n                Err(e) => {\n                    return Err(Error::new(\n                        ErrorKind::SyntaxError,\n                        format!(\"Invalid value for or_splitter (expected string): {e}\"),\n                    ))\n                }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jinja-runtime/src/output_format/mod.rs#L43-L79","documentation":"The `prefix` kwarg of BAML's `output_format()` must be a string or null. When `kwargs.get::<Option<String>>(\"prefix\")` fails to deserialize the provided value, the filter wraps the minijinja deserialization error in this SyntaxError. It guards the typed options contract of the filter.","triggerScenarios":"Calling `output_format(prefix=123)`, `output_format(prefix=[\"a\"])`, `output_format(prefix=true)` or passing any non-string, non-null value for `prefix` in a BAML template.","commonSituations":"Interpolating a variable of the wrong type into the kwarg (e.g. a number or list from prompt metadata); typos that bind the wrong variable; building kwargs dynamically and losing type guarantees.","solutions":["Pass a string or null: `output_format(prefix=\"My prefix:\")` or omit `prefix` entirely.","Coerce numbers/other values to strings before passing, e.g. `prefix=idx | string`.","Verify the interpolated variable actually holds a string in your BAML function/client code."],"exampleFix":"// before\n{{ output_format(prefix=42) }}\n// after\n{{ output_format(prefix=\"42\") }}","handlingStrategy":"type-guard","validationCode":"// Before rendering, ensure prefix is string or null\nif (prefix !== null && typeof prefix !== \"string\") throw new Error(`prefix must be string|null, got ${typeof prefix}`);","typeGuard":"const isStringOrNull = (v) => v === null || v === undefined || typeof v === \"string\";","tryCatchPattern":"try {\n  render(prompt);\n} catch (e) {\n  if (String(e).includes(\"Invalid value for prefix\")) console.error(\"Fix output_format(prefix=...) to a string or null\");\n  throw e;\n}","preventionTips":["Coerce dynamic values with the Jinja `| string` filter before passing as prefix.","Omit the kwarg instead of passing other sentinel types.","Type the variable as string|null in the code that builds the template context."],"tags":["jinja","baml","type-mismatch","template"],"backgroundTag":"invalid-argument-value","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"}