vectordotdev/vector · error

Unable to serialize VRL value

Error message

Unable to serialize VRL value

What it means

In vector-config's VRL integration, `ToValue for vrl::Value` serializes a VRL runtime value to JSON and explicitly panics with "Unable to serialize VRL value" on failure. The doc comment notes this is not expected under normal circumstances because VRL values are designed to be JSON-representable. Because `to_value` has no error channel, any serialization failure surfaces as a panic during schema/config generation.

Solutions

  1. Check whether the VRL value contains non-JSON-representable variants (non-string map keys, NaN/Inf floats) before calling to_value
  2. Normalize the value first (convert regexes to their string form, replace non-finite floats)
  3. If calling from your own code, use serde_json::to_value directly and handle the Result instead of relying on ToValue

Example fix

// before
let v: serde_json::Value = value.to_value();
// after
let v = serde_json::to_value(&value)
    .unwrap_or_else(|e| panic!("Unable to serialize VRL value: {e}")); // keeps cause; or handle Err
Defensive patterns

Strategy: validation

Validate before calling

// Guard against non-JSON-representable VRL values first:
if !serde_json::to_value(&vrl_value).is_ok() {
    eprintln!("VRL value contains non-JSON-representable data");
}

Type guard

fn is_json_safe(vrl_value: &vrl::Value) -> bool {
    serde_json::to_value(vrl_value).is_ok()
}

Try / catch

// to_value panics by design; isolate if calling externally:
let result = std::panic::catch_unwind(|| vrl_value.to_value());

Prevention

When it happens

Trigger: Calling `vrl::Value::to_value()` while generating schemas or metadata when the VRL value's serde representation is rejected by serde_json — e.g. a value containing non-string map keys (regexes/bytes variants) or an NaN/infinite float that serde_json cannot encode.

Common situations: Schema generation for transforms whose config embeds VRL values; constructing VRL values programmatically (with regex or bytes objects) and passing them through config metadata serialization.

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


AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16). Data as JSON: /api/errors/31e912511d4ab8c8. Report an issue: GitHub.

Appendix: source

Thrown at lib/vector-config/src/external/vrl.rs:66

    fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> {
        // We don't have any constraints on the inputs
        Ok(SchemaObject::default())
    }
}

impl ToValue for VrlValue {
    /// Converts a `VrlValue` into a `serde_json::Value`.
    ///
    /// This conversion should always succeed, though it may result in a loss
    /// of type information for some value types.
    ///
    /// # Panics
    ///
    /// This function will panic if serialization fails, which is not expected
    /// under normal circumstances.
    fn to_value(&self) -> Value {
        serde_json::to_value(self).expect("Unable to serialize VRL value")
    }
}

View on GitHub (pinned to bdb87aeaa4)