dbt-labs/dbt-core · error · minijinja::Error (InvalidOperation)

write function requires payload argument

Error message

write function requires payload argument

What it means

The write() function exposed on the run-node context requires at least one argument: the payload to write. Called with no arguments, it raises immediately because there is nothing to serialize to the artifact file.

Solutions

  1. Pass the payload string as the first argument: {{ write(my_payload) }}.
  2. Check that the variable holding the payload is not accidentally omitted during a refactor.
  3. Guard the call site: only call write when content is available.

Example fix

-- before
{{ write() }}
-- after
{{ write(log_message | string) }}
Defensive patterns

Strategy: validation

Validate before calling

-- Jinja
{% if payload is defined and payload is not none %}
  {{ write(payload | string) }}
{% endif %}

Try / catch

// Rust-side programmatic invocation
if args.is_empty() {
    return Err(Error::new(ErrorKind::InvalidOperation, "write requires a payload argument"));
}

Prevention

When it happens

Trigger: Invoking the write callable from Jinja with zero arguments, e.g. {{ write() }} or assigning write to a variable and calling it without args.

Common situations: Typo where an argument is computed conditionally and the call still happens; macro refactors that drop the payload argument; dynamic dispatch where args list is built programmatically and ends up empty.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07). Data as JSON: /api/errors/3a00b827f934d43b. Report an issue: GitHub.

Appendix: source

Thrown at crates/dbt-jinja-utils/src/phases/run/run_node_context.rs:690

/// Context function that writes a payload to file
#[derive(Debug)]
pub struct WriteConfig {
    /// The resource type string (see `fusion::node::NodeType`)
    pub resource_type: String,
    /// Absolute target/run path for this node.
    pub run_file_path: PathBuf,
}

impl Object for WriteConfig {
    fn call(
        self: &Arc<Self>,
        _state: &State<'_, '_>,
        args: &[MinijinjaValue],
        _listeners: &[Rc<dyn RenderingEventListener>],
    ) -> Result<MinijinjaValue, Error> {
        if args.is_empty() {
            return Err(Error::new(
                ErrorKind::InvalidOperation,
                "write function requires payload argument".to_string(),
            ));
        }

        // Extract payload from args
        let payload = match args[0].as_str() {
            Some(s) => s,
            None => {
                return Err(Error::new(
                    ErrorKind::InvalidOperation,
                    "Failed to convert payload to string".to_string(),
                ));
            }
        };

        // Write the file
        match write_file(&self.run_file_path, &self.resource_type, payload) {

View on GitHub (pinned to 0267ce9170)