windmill-labs/windmill · error

Expected array of strings for `type` field

Error message

Expected array of strings for `type` field

What it means

When `type` is given as an array (union type), `from_value` maps each element through `JsonPrimitiveType::from_str`, which requires a string. Any non-string element in the `type` array (or a null entry) fails with this error.

Source

Thrown at backend/windmill-common/src/schema.rs:172

        }

        let mut schema_rules = vec![];

        let typ = val.get("type").ok_or(anyhow!("Missing `type` field"))?;

        if let Some(typ) = typ.as_str() {
            schema_rules.append(&mut SchemaValidationRule::from_primitive(
                &JsonPrimitiveType::from_str(typ)?,
                val,
            )?);
        } else if let Some(typ_arr) = typ.as_array() {
            let typ_arr = typ_arr
                .into_iter()
                .map(|v| {
                    SchemaValidationRule::from_primitive(
                        &JsonPrimitiveType::from_str(
                            v.as_str()
                                .ok_or(anyhow!("Expected array of strings for `type` field"))?,
                        )?,
                        v,
                    )
                })
                .collect::<Result<Vec<Vec<SchemaValidationRule>>, anyhow::Error>>()?;

            schema_rules.push(SchemaValidationRule::IsUnionType(typ_arr));
        } else {
            return Err(anyhow!(
                "Unsupported value for type field, expected string or string array"
            )
            .into());
        }

        if let Some(enum_variants) = val.get("enum") {
            let variants = enum_variants
                .as_array()
                .ok_or(anyhow!("enum variants are not in an array"))?

View on GitHub (pinned to e474e8803c)

Solutions

  1. Ensure every entry in the `type` array is a valid primitive string (string, number, integer, boolean, object, array).
  2. Remove `null` entries; express nullability the way Windmill supports (e.g. anyOf with an empty variant) instead of "null".
  3. Quote values in YAML so they stay strings.

Example fix

// before
{ "type": ["string", "null"] }
// after
{ "anyOf": [ { "title": "Value", "type": "string" }, { "title": "Empty", "type": "object", "properties": {} } ] }
Defensive patterns

Strategy: validation

Validate before calling

const s = JSON.parse(schemaRaw);
if (Array.isArray(s.type)) {
  const bad = s.type.filter(t => typeof t !== "string");
  if (bad.length) throw new Error("Every entry in the `type` array must be a primitive string");
}

Type guard

function hasStringTypeUnion(s) {
  return !Array.isArray(s?.type) || s.type.every(t => typeof t === "string");
}

Try / catch

try {
  await deploy(schema);
} catch (e) {
  if (String(e.message).includes("Expected array of strings for `type` field")) {
    throw new Error("Use only primitive strings in the type array; avoid null entries");
  } else throw e;
}

Prevention

When it happens

Trigger: A schema like `"type": ["string", 1]` or `"type": ["string", null]` parsed by `from_value` during app/flow schema ingestion.

Common situations: Programmatic schema generation inserting non-string type ids; YAML unquoted types coercing to numbers/booleans; JSON Schema draft features (e.g. `"type": ["string", "null"]`) where the null member is not a Windmill primitive.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/2532fb6816129e15. Report an issue: GitHub.