{"record":{"id":"fbe1737dcc8f3934","repo":"BoundaryML/baml","slug":"baml-errors-invalidargument","errorCode":"baml.errors.InvalidArgument","errorMessage":"invalid argument: {message}","messagePattern":"invalid argument: (.+?)","errorType":"error_code","errorClass":"VmBamlError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm_types/src/errors.rs","lineNumber":113,"sourceCode":"    /// that does not match its declared `throws` contract `E`. Surfaces in\n    /// BAML as `baml.panics.HostContractViolation`.\n    ///\n    /// `class_name` / `language` are populated when the violation arose from\n    /// a host throw (echoing the offending host exception's identity) and\n    /// `None` when it arose from a wrong-type return (no exception class to\n    /// echo).\n    #[error(\"host contract violation: {message} [class={class_name:?}, lang={language:?}]\")]\n    HostContractViolation {\n        message: String,\n        class_name: Option<String>,\n        language: Option<String>,\n    },\n}\n\n/// An error value from the BAML standard library. Maps 1:1 to a `baml.errors.*` class.\n#[derive(Debug, Error, PartialEq, Clone)]\npub enum VmBamlError {\n    #[error(\"invalid argument: {message}\")]\n    InvalidArgument { message: String },\n\n    #[error(\"parse error: {message}\")]\n    ParseError { message: String },\n\n    #[error(\"I/O error: {message}\")]\n    Io { message: String },\n\n    #[error(\"timeout: {message}\")]\n    Timeout {\n        message: String,\n        duration_ms: Option<i64>,\n    },\n\n    #[error(\"unsupported: {message}\")]\n    Unsupported { message: String },\n\n    #[error(\"access error: {message}\")]","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm_types/src/errors.rs#L95-L131","documentation":"An error value from the BAML standard library, mapping 1:1 to the `baml.errors.InvalidArgument` class. It is raised when a stdlib function receives an argument that is well-typed but has an unacceptable value or form for that operation.","triggerScenarios":"Calling a BAML stdlib function (string, JSON, math, etc.) with a parameter value it cannot accept — e.g. an out-of-domain numeric argument, an invalid mode/flag string, or a malformed input to a parsing function that specifically validates arguments.","commonSituations":"Hardcoded option strings that don't match accepted values; passing 0 or negative numbers where positive values are required; refactors that change argument order or semantics; translating examples from other languages with different stdlib contracts.","solutions":["Read the error message (the `message` field names the offending argument and reason) and correct the argument value at the call site.","Validate arguments before calling the stdlib function (range checks, allowed-value lists).","Check the function's documentation for accepted parameter values/types.","Catch `baml.errors.InvalidArgument` in BAML to handle bad input from users gracefully."],"exampleFix":"// before\nlet n = json.parseInt(str, 37); // invalid radix\n// after\nlet n = json.parseInt(str, 16); // valid radix\n","handlingStrategy":"validation","validationCode":"// BAML: validate arguments before the stdlib call\nif radix < 2 || radix > 36 {\n  return err(\"radix must be 2..36\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  let n = std.parse_int(s, radix);\n} catch e: baml.errors.InvalidArgument {\n  return handle_bad_input(e.message);\n}","preventionTips":["Check allowed parameter values in the stdlib docs before use.","Validate user-derived inputs before passing them to stdlib functions.","Use constants/enums for option strings instead of raw literals.","Cover stdlib calls with tests including edge-case arguments."],"tags":["stdlib","invalid-argument","validation","baml"],"backgroundTag":"invalid-argument","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"}