{"record":{"id":"0c496620fda46fb2","repo":"dbt-labs/dbt-core","slug":"model-constraints-e","errorCode":null,"errorMessage":"model_constraints: {e}","messagePattern":"model_constraints: (.+?)","errorType":"exception","errorClass":"minijinja::Error::SerdeDeserializeError","httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/adapter/adapter_impl.rs","lineNumber":4677,"sourceCode":"                    minijinja::Error::new(\n                        minijinja::ErrorKind::InvalidOperation,\n                        \"existing_columns must contain Column objects\",\n                    )\n                })\n            })\n            .collect::<Result<Vec<_>, _>>()?;\n\n        let model_columns_map: BTreeMap<String, DbtColumn> =\n            minijinja_value_to_typed_struct(model_columns.clone()).map_err(|e| {\n                minijinja::Error::new(\n                    minijinja::ErrorKind::SerdeDeserializeError,\n                    format!(\"model_columns: {e}\"),\n                )\n            })?;\n\n        let model_constraints_vec: Vec<ModelConstraint> =\n            minijinja_value_to_typed_struct(model_constraints.clone()).map_err(|e| {\n                minijinja::Error::new(\n                    minijinja::ErrorKind::SerdeDeserializeError,\n                    format!(\"model_constraints: {e}\"),\n                )\n            })?;\n\n        let column_refs: Vec<DbtColumnRef> = model_columns_map\n            .values()\n            .map(|c| Arc::new(c.clone()))\n            .collect();\n\n        let (not_nulls, typed_constraints) = if contract_enforced {\n            typed_constraint::parse_constraints(&column_refs, &model_constraints_vec).map_err(\n                |e| {\n                    minijinja::Error::new(\n                        minijinja::ErrorKind::InvalidOperation,\n                        format!(\"parse_constraints: {e}\"),\n                    )\n                },","sourceCodeStart":4659,"sourceCodeEnd":4695,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/adapter/adapter_impl.rs#L4659-L4695","documentation":"This error is raised when converting the `model_constraints` Minijinja Value into a typed `Vec<ModelConstraint>` struct via `minijinja_value_to_typed_struct` fails during model materialization in dbt-adapter. The library throws it because the constraints value passed from the Jinja/manifest layer did not deserialize into the expected ModelConstraint shape, meaning the model's constraint definitions are malformed or of an unexpected type. It surfaces as a SerdeDeserializeError wrapping the underlying serde message.","triggerScenarios":"Calling the adapter's model materialization path (near adapter_impl.rs:4677) with a `model_constraints` value that is not a serializable list of constraint objects — e.g. a dict, a string, or constraints missing required fields like `type`.","commonSituations":"A model defines `constraints` in YAML with a wrong structure (e.g. constraint given as a plain string instead of a dict with `type:`), a custom materialization passes incompatible data into model_constraints, or a version mismatch between the manifest schema and the ModelConstraint struct.","solutions":["Check the model's YAML `constraints` definitions: each must be a mapping with a valid `type` key (not_null, unique, primary_key, foreign_key, check, etc.)","Inspect the underlying serde message appended after 'model_constraints: ' to identify the exact field that failed to deserialize","Ensure the caller producing `model_constraints` (manifest node or custom materialization) passes a list of constraint structs, not strings or dicts of another shape","Align dbt-core and adapter versions so the ModelConstraint schema matches what the manifest emits"],"exampleFix":"// before (model.yml)\nconstraints:\n  - not_null\n// after\nconstraints:\n  - type: not_null\n    columns: [id]","handlingStrategy":"validation","validationCode":"// caller-side guard\nif (!Array.isArray(model_constraints) || model_constraints.some(c => typeof c !== 'object' || c === null || !('type' in c))) {\n  throw new Error('model_constraints must be a list of constraint objects each with a `type` field');\n}","typeGuard":"fn is_model_constraints(v: &Value) -> bool {\n    v.clone().try_into_object().map(|o| o.len() >= 0).is_ok()\n}","tryCatchPattern":"match minijinja_value_to_typed_struct::<Vec<ModelConstraint>>(model_constraints.clone()) {\n    Ok(v) => v,\n    Err(e) => return Err(format!(\"model_constraints deserialization failed: {e} - verify constraint YAML shape\")),\n}","preventionTips":["Validate model YAML constraints against the dbt constraints schema before run","Keep dbt-core and adapter versions aligned","Log the serialized model_constraints value on failure for diagnosis"],"tags":["serde","constraints","deserialization","minijinja"],"backgroundTag":"schema-validation-failed","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}