{"record":{"id":"8e5ceb6443d224cc","repo":"dbt-labs/dbt-core","slug":"local-md5-s-argument-must-be-a-string","errorCode":null,"errorMessage":"local_md5's argument must be a string","messagePattern":"local_md5's argument must be a string","errorType":"validation","errorClass":"InvalidOperation","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/functions/base.rs","lineNumber":1042,"sourceCode":"/// Args:\n///     value: String to hash\n///\n/// Example:\n/// ```jinja\n/// {% set hash = local_md5(\"hello\") %}\n/// -- Returns \"5d41402abc4b2a76b9719d911017c592\"\n/// ```\npub fn local_md5_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {\n    move |args: &[Value], _kwargs: Kwargs| -> Result<Value, Error> {\n        if args.len() != 1 {\n            return Err(Error::new(\n                ErrorKind::InvalidOperation,\n                \"local_md5 requires exactly 1 argument\",\n            ));\n        }\n\n        let value = args[0].as_str().ok_or_else(|| {\n            Error::new(\n                ErrorKind::InvalidOperation,\n                \"local_md5's argument must be a string\",\n            )\n        })?;\n        // Create MD5 hasher\n        let result = format!(\"{:x}\", md5::compute(value.as_bytes()));\n        Ok(Value::from(result))\n    }\n}\n\n/// Parse a dictionary of lists into a BTreeMap<String, Vec<String>>\nfn parse_dict_of_lists(dict: &Value) -> Result<IndexMap<String, Vec<String>>, Error> {\n    let mut result = IndexMap::new();\n\n    // Iterate over the keys in the dictionary\n    for key in dict.try_iter()? {\n        // Get the value associated with the key\n        let value = dict.get_item(&key)?;","sourceCodeStart":1024,"sourceCodeEnd":1060,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/functions/base.rs#L1024-L1060","documentation":"`local_md5` hashes strings only; when its single argument is not a string (e.g. a number, boolean, list, or undefined value) the `as_str()` conversion fails and this error is raised. It exists to fail fast rather than hashing a Debug representation that would differ from dbt's expected output.","triggerScenarios":"Calling `{{ local_md5(123) }}`, `{{ local_md5(my_list) }}`, or `{{ local_md5(undefined_var) }}` — any non-string value, including values rendered from YAML that arrive as ints/bools.","commonSituations":"Hashing a numeric ID directly from the warehouse, an undefined variable due to a missing config key, or a column value that dbt typed as a number.","solutions":["Convert to string before hashing: `local_md5(value | string)`","Guard undefined variables with a default: `local_md5(var | default(\"\"))`","Ensure the source column/variable is a string type upstream"],"exampleFix":"// before\n{% set h = local_md5(user_id) %}\n// after\n{% set h = local_md5(user_id | string) %}","handlingStrategy":"type-guard","validationCode":"{% if value is not string %}{% set value = value | string %}{% endif %}","typeGuard":"{% macro as_str(v) %}{% if v is string %}{{ v }}{% else %}{{ v | string }}{% endif %}{% endmacro %}","tryCatchPattern":null,"preventionTips":["Apply the `| string` filter before hashing non-string values","Default undefined vars: var('x', '') | string","Confirm source columns are typed as strings"],"tags":["jinja","type-error","md5"],"backgroundTag":"type-mismatch","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}