{"record":{"id":"b16acdca8c1f2375","repo":"dbt-labs/dbt-core","slug":"compilation-error-for-from","errorCode":null,"errorMessage":"Compilation Error for {} from {}: {}","messagePattern":"Compilation Error for (.+?) from (.+?): (.+?)","errorType":"exception","errorClass":"minijinja::Error (InvalidOperation)","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/functions/base.rs","lineNumber":1216,"sourceCode":"            // [{\"name\": ..., \"data_type\": ..., \"formatted\": ...},...]\n            \"raise_contract_error\" => {\n                let mut args = ArgParser::new(args, None);\n                let yaml_columns = args\n                    .get::<Value>(\"yaml_columns\")\n                    .unwrap_or(Value::UNDEFINED);\n                let sql_columns = args.get::<Value>(\"sql_columns\").unwrap_or(Value::UNDEFINED);\n                let column_diff_table: &Arc<AgateTable> =\n                    get_contract_mismatches(yaml_columns, sql_columns)?;\n                let column_diff_display = column_diff_table\n                    .display()\n                    .with_max_rows(50)\n                    .with_max_columns(50)\n                    .with_max_column_width(50);\n                let message = format_args!(\n                    \"This model has an enforced contract that failed.\\n Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.\\n\\n{column_diff_display}\"\n                );\n                if let Some((node_id, file_path)) = node_metadata_from_state(state) {\n                    Err(Error::new(\n                        ErrorKind::InvalidOperation,\n                        format!(\n                            \"Compilation Error for {} from {}: {}\",\n                            node_id,\n                            file_path.display(),\n                            message\n                        ),\n                    ))\n                } else {\n                    Err(Error::new(\n                        ErrorKind::InvalidOperation,\n                        format!(\"Compilation Error: {message}\"),\n                    ))\n                }\n            }\n            // (column_names)\n            // [\"column1\", \"column2\"]\n            \"column_type_missing\" => {","sourceCodeStart":1198,"sourceCodeEnd":1234,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/functions/base.rs#L1198-L1234","documentation":"A model declares an enforced contract (contract.enforced: true) whose YAML column name/data_type/count does not match the columns the model's SQL actually produces. dbt renders a column-level diff and fails compilation for that node, attaching the node id and file path when available.","triggerScenarios":"Running or building a contracted model where the SQL query returns columns that differ in name, data_type, or number from the columns listed in the model's YAML `columns:` block (diff is capped at 50 columns/50-char width for display).","commonSituations":"Adding a column to the SQL but forgetting the YAML contract; renaming a column; changing a data type (e.g. varchar width, int to bigint) in the model; dbt version upgrades that tighten type checking.","solutions":["Align the YAML `columns:` block (names, data_type, count) with the model's actual SELECT output.","If the change is intentional, update the contract in the YAML to the new schema.","Temporarily set `contract.enforced: false` while iterating, then re-enable and fix.","Read the rendered column diff in the error to see exactly which columns mismatch."],"exampleFix":"# before (models/my_model.yml)\ncolumns:\n  - name: id\n    data_type: int64\n# model returns id BIGINT, user_name TEXT\n\n# after\ncolumns:\n  - name: id\n    data_type: bigint\n  - name: user_name\n    data_type: text","handlingStrategy":"validation","validationCode":"# Validate the contract YAML against the model's SELECT before running dbt\nimport yaml\nspec = yaml.safe_load(open('models/my_model.yml'))\nyaml_cols = [(c['name'], c['data_type']) for c in spec['models'][0]['columns']]\nactual_cols = [(r[0], r[1]) for r in cursor.description]  # from a test run of the model SQL\nassert len(yaml_cols) == len(actual_cols), 'column count mismatch'\nassert [n for n, _ in yaml_cols] == [n for n, _ in actual_cols], 'column names mismatch'","typeGuard":null,"tryCatchPattern":"// In the runner\nif let Err(e) = dbt_build(&[\"--select\", \"my_model\"]) {\n    if e.message.contains(\"enforced contract that failed\") {\n        // print the column diff and halt the pipeline before downstream nodes\n        return Err(e);\n    }\n    return Err(e);\n}","preventionTips":["Update the YAML columns block in the same PR as any model SQL column change.","Keep data_type in YAML exactly matching warehouse types (watch varchar widths, int sizes).","Run `dbt compile` + a dry query of the model SQL in CI to diff columns before merge.","Only enable contract.enforced on stable models initially."],"tags":["dbt","jinja","contract","schema-validation","compilation"],"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-14T16:17:12.679Z"}