dbt-labs/dbt-core · error
Failed to serialize object
Error message
Failed to serialize object
What it means
This panic comes from `serde_yaml::to_value` (dbt_yaml) while serializing the node's deprecated raw config into a YAML value during run-phase node context building. Serialization can only fail here if the config contains non-string map keys or other YAML-incompatible structures, which indicates an invariant violation in how the config was constructed upstream rather than bad user YAML. The library treats this as unrecoverable and panics via `.expect`.
Source
Thrown at crates/dbt-jinja-utils/src/phases/run/run_node_context.rs:128
let model = node.serialize();
let common_attr = node.common();
let base_attr = node.base();
let resource_type = node.resource_type();
// Create a relation for 'this' using config values
let this_relation = dbt_adapter::relation::RelationObject::new(Arc::from(
dbt_adapter::relation::do_create_relation(
adapter_type,
base_attr.database.clone(),
base_attr.schema.clone(),
Some(base_attr.alias.clone()),
None,
base_attr.quoting,
)
.unwrap(),
))
.into_value();
let config_yml = dbt_yaml::to_value(deprecated_config).expect("Failed to serialize object");
// `ModelConfig`/`SeedConfig`/`SnapshotConfig` serialize hooks under the underscored
// name; `FunctionConfig` doubles as its own manifest type and so uses dbt-core's
// hyphenated key. Accept either.
let hooks_of = |underscored: &str, hyphenated: &str| {
config_yml
.get(underscored)
.or_else(|| config_yml.get(hyphenated))
};
let pre_hooks = hooks_of("pre_hook", "pre-hook").map(|pre_hook| {
let values: Vec<HookConfig> = match pre_hook {
YmlValue::String(_, _) | YmlValue::Mapping(_, _) => {
parse_hook_item(pre_hook).into_iter().collect()
}
YmlValue::Sequence(arr, _) => arr.iter().filter_map(parse_hook_item).collect(),
YmlValue::Null(_) => vec![],
_ => {View on GitHub (pinned to 0267ce9170)
Solutions
- Reproduce with the failing model/seed/snapshot and inspect the rendered `config` dict for non-string or exotic map keys
- Update to the latest dbt-fusion/dbt-jinja-utils version — config coercion fixes often land here
- Check the custom adapter/materialization for code that inserts into node config with non-String keys
- Capture RUST_BACKTRACE=1 output and file a bug with the model SQL and config block
Example fix
// before (internal, illustrative)
let config_yml = dbt_yaml::to_value(deprecated_config).expect("Failed to serialize object");
// after
let config_yml = dbt_yaml::to_value(&deprecated_config)
.map_err(|e| ErrFatal.load_error(format!("failed to serialize node config: {e}")))?; Defensive patterns
Strategy: validation
Validate before calling
// sanity-check config keys before serializing
fn serializable_config(cfg: &serde_json::Value) -> bool {
cfg.as_object().map(|m| m.keys().all(|k| !k.is_empty())).unwrap_or(false)
}
if !serializable_config(&deprecated_config) { return Err(...); } Try / catch
// replace .expect with error propagation
let config_yml = dbt_yaml::to_value(&deprecated_config)
.map_err(|e| format!("config serialization failed: {e}"))?; Prevention
- Keep node config map keys as strings after Jinja rendering
- Keep adapter/parser crates on matching versions
- Reproduce with RUST_BACKTRACE=1 and report non-serializable configs upstream
When it happens
Trigger: `build_model_context_fields` calls `dbt_yaml::to_value(deprecated_config)` and the `DeprecatedConfig`/config value contains keys or values that cannot round-trip into a YAML mapping (e.g. non-string map keys produced by templating, or a poisoned config built by an adapter hook).
Common situations: Custom materializations or adapters injecting config entries with unexpected key types; internal dbt version mismatches where `ModelConfig`/`SeedConfig`/`SnapshotConfig`/`FunctionConfig` hooks were stored under a key type the serializer rejects; exotic user configs surviving Jinja rendering as non-scalar keys.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- Failed to serialize merged node config to dbt_yaml::Value fo
- Version '{:?}' does not meet the required format
- Failed to convert value to YAML: {err}
- invalid serialized time precision
- invalid serialized timestamp precision
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/d8a60f16826cf5ad.
Report an issue: GitHub.