{"record":{"id":"06da3083ab945274","repo":"BoundaryML/baml","slug":"unexpected-token-token-in-script-body-script-bodies-have-the","errorCode":null,"errorMessage":"unexpected token `{token}` in script body. Script bodies have the shape `[--function <name>] [-- <target-args>...]`.","messagePattern":"unexpected token `(.+?)` in script body\\. Script bodies have the shape `\\[--function <name>\\] \\[-- <target-args>\\.\\.\\.\\]`\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/run_command.rs","lineNumber":123,"sourceCode":"            i += 1;\n            if i < tokens.len() {\n                function = Some(tokens[i].clone());\n                i += 1;\n            } else {\n                anyhow::bail!(\"script body has `--function` without a value\");\n            }\n            continue;\n        }\n\n        if let Some(stripped) = token.strip_prefix(\"--\") {\n            anyhow::bail!(\n                \"unknown run-verb flag `--{stripped}` in script body. \\\n                 Only `--function <name>` is recognized before `--`; \\\n                 put target arguments after `--`.\"\n            );\n        }\n\n        anyhow::bail!(\n            \"unexpected token `{token}` in script body. \\\n             Script bodies have the shape `[--function <name>] [-- <target-args>...]`.\"\n        );\n    }\n\n    Ok(ScriptExpansion {\n        function,\n        extra_args,\n    })\n}\n\n// ============================================================================\n// CLI Args\n// ============================================================================\n\n/// Run a BAML function, script, or expression.\n///\n/// Choose one execution mode: a positional function or script, one or more","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/run_command.rs#L105-L141","documentation":"Parse guard for script bodies in baml.toml [scripts]: a bare token appeared where only `--function <name>` or the `--` separator is allowed. This usually means target arguments were written without the required `--` separator in front of them.","triggerScenarios":"`parse_script_body` hits a token that is neither `--function`, nor a `--`-prefixed flag, nor the `--` separator — e.g. `[\"MyFunc\"]` or `[\"--function\", \"F\", \"extra\"]`.","commonSituations":"Omitting `--function` before the function name; forgetting `--` before target args; positional arguments accidentally left in the body.","solutions":["Prefix the function name with `--function`","Put any positional/target arguments after `--`","Remove stray tokens that don't fit the `[--function <name>] [-- <args>...]` shape"],"exampleFix":"// before\n[\"MyFunction\", \"arg\"]\n// after\n[\"--function\", \"MyFunction\", \"--\", \"arg\"]","handlingStrategy":"validation","validationCode":"function validateBodyShape(tokens) {\n  const sep = tokens.indexOf('--');\n  const head = sep === -1 ? tokens : tokens.slice(0, sep);\n  const ok = head.length === 0 || (head[0] === '--function' && head.length <= 2);\n  if (!ok) throw new Error('body must be [--function <name>] [-- <target-args>...]');\n}","typeGuard":null,"tryCatchPattern":"try { await baml.run(tokens); } catch (e) { if (String(e).includes('unexpected token')) { console.error('Correct shape: [--function <name>] [-- <target-args>...]'); } else throw e; }","preventionTips":["Never put bare positional tokens before `--`","Prefix function names with `--function`","Lint script bodies against the documented grammar"],"tags":["cli","argument-parsing","baml"],"backgroundTag":"invalid-cli-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}