{"record":{"id":"bed6773d39b831c8","repo":"BoundaryML/baml","slug":"expected-true-or-false-got-raw","errorCode":null,"errorMessage":"expected `true` or `false`, got `{raw}`","messagePattern":"expected `true` or `false`, got `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_exec/src/auto_cli.rs","lineNumber":64,"sourceCode":"\n        RuntimeTy::Int { .. } => {\n            let v: i64 = raw\n                .parse()\n                .with_context(|| format!(\"expected integer, got `{raw}`\"))?;\n            Ok(BexExternalValue::Int(v))\n        }\n\n        RuntimeTy::Float { .. } => {\n            let v: f64 = raw\n                .parse()\n                .with_context(|| format!(\"expected float, got `{raw}`\"))?;\n            Ok(BexExternalValue::Float(v))\n        }\n\n        RuntimeTy::Bool { .. } => match raw {\n            \"true\" => Ok(BexExternalValue::Bool(true)),\n            \"false\" => Ok(BexExternalValue::Bool(false)),\n            _ => anyhow::bail!(\"expected `true` or `false`, got `{raw}`\"),\n        },\n\n        RuntimeTy::Null { .. } => {\n            if raw == \"null\" {\n                Ok(BexExternalValue::Null)\n            } else {\n                anyhow::bail!(\"expected `null`, got `{raw}`\")\n            }\n        }\n\n        // `T?` is `T | null`: accept the literal `null`, else parse the value\n        // against the non-null inner type.\n        RuntimeTy::Union(..) if ty.is_nullable_union() => {\n            if raw == \"null\" {\n                Ok(BexExternalValue::Null)\n            } else {\n                parse_cli_value(raw, &ty.strip_null())\n            }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_exec/src/auto_cli.rs#L46-L82","documentation":"When a CLI parameter's runtime type is Bool, auto-CLI parses the raw string with an exact match against `true` or `false`. Any other spelling is rejected with this message. This prevents silent coercion of arbitrary strings into booleans.","triggerScenarios":"Calling `parse_cli_value` for a `RuntimeTy::Bool` parameter with a raw value other than exactly `true` or `false` (e.g. `True`, `1`, `yes`, `TRUE`); typically via `baml run -- <param> <value>`.","commonSituations":"Passing shell-style booleans like `1`/`0` or `yes`/`no`, capitalizing `True`/`False` out of habit from Python, or quoting values oddly in shell scripts.","solutions":["Pass the literal lowercase `true` or `false` after `--` for boolean parameters.","Alternatively deliver the value via `--json-args '{\"<param>\": true}'` so JSON parsing handles it.","Check `baml run <target> --help` for the parameter's declared type."],"exampleFix":"// before\nbaml run myFunc -- --flag 1\n\n// after\nbaml run myFunc -- --flag true","handlingStrategy":"validation","validationCode":"fn valid_cli_bool(raw: &str) -> bool { matches!(raw, \"true\" | \"false\") }","typeGuard":"fn as_cli_bool(raw: &str) -> Option<bool> {\n    match raw { \"true\" => Some(true), \"false\" => Some(false), _ => None }\n}","tryCatchPattern":"match result {\n    Ok(v) => use(v),\n    Err(e) if e.to_string().contains(\"expected `true` or `false`\") => {\n        eprintln!(\"boolean flags accept only lowercase true/false: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always quote boolean flag values in shell scripts","Use lowercase true/false, never 1/0 or True/False","Prefer --json-args for programmatic invocation"],"tags":["cli","boolean","parsing","baml"],"backgroundTag":"invalid-flag-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"}