{"record":{"id":"ad93041bf9520112","repo":"BoundaryML/baml","slug":"expected-null-got-raw","errorCode":null,"errorMessage":"expected `null`, got `{raw}`","messagePattern":"expected `null`, got `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_exec/src/auto_cli.rs","lineNumber":71,"sourceCode":"\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            }\n        }\n\n        RuntimeTy::Enum(type_name, _) => Ok(BexExternalValue::Variant {\n            enum_name: type_name.display_name().to_string(),\n            variant_name: raw.to_string(),\n        }),\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_exec/src/auto_cli.rs#L53-L89","documentation":"For a parameter whose runtime type is Null, auto-CLI only accepts the exact literal string `null`. Any other raw value fails with this error. Nullable unions (`T?`) are handled separately: `null` short-circuits, otherwise the inner type parses the value.","triggerScenarios":"Passing a non-`null` string to a CLI parameter typed as Null; `parse_cli_value` bails when `raw != \"null\"` for `RuntimeTy::Null`.","commonSituations":"Typos like `None`, `nil`, `NULL`, or `none` when trying to pass an explicit null from the command line.","solutions":["Pass the exact lowercase string `null` for a null-valued parameter.","Use `--json-args '{\"<param>\": null}'` for JSON-native null.","If the parameter should hold a real value, fix the function signature - a bare Null-typed param only accepts `null`."],"exampleFix":"// before\nbaml run myFunc -- --opt NULL\n\n// after\nbaml run myFunc -- --opt null","handlingStrategy":"validation","validationCode":"fn valid_cli_null(raw: &str) -> bool { raw == \"null\" }","typeGuard":"fn as_cli_null(raw: &str) -> Option<()> { if raw == \"null\" { Some(()) } else { None } }","tryCatchPattern":"match result {\n    Ok(v) => use(v),\n    Err(e) if e.to_string().contains(\"expected `null`, got\") => {\n        eprintln!(\"use the literal lowercase string null: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Spell null exactly as lowercase `null` (not NULL/None/nil)","Prefer omitting the flag or using --json-args null for nullable params","Check the parameter's declared type via --help"],"tags":["cli","null","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"}