Budibase/budibase · error · Error

Invalid file input – source and file type do not match

Error message

Invalid file input – source and file type do not match

What it means

run() in the AI extract step dispatches on inputs.source: URL source expects a string URL, ATTACHMENT source expects a file object. If neither branch matches — source and the actual shape of file disagree — it throws this mismatch error.

Source

Thrown at packages/server/src/automations/steps/ai/extract.ts:268

      } catch {
        return value
      }
    }

    const file =
      inputs.source === DocumentSourceType.URL
        ? inputs.file
        : tryParse(inputs.file)

    if (inputs.source === DocumentSourceType.URL && typeof file === "string") {
      extractInput = await processUrlFile(file, inputs.fileType, llm)
    } else if (
      inputs.source === DocumentSourceType.ATTACHMENT &&
      typeof file !== "string"
    ) {
      extractInput = await processAttachmentFile(file, llm)
    } else {
      throw new Error("Invalid file input – source and file type do not match")
    }

    const output = getOutputFromSchema(inputs.schema)
    const modelMessages = buildExtractModelMessages(extractInput)
    const providerOptions = llm.providerOptions?.(false)
    const response = await generateText({
      model: llm.chat,
      messages: modelMessages,
      providerOptions,
      output,
      experimental_download: downloadAssetsForExtract,
    })
    if (!response.output || response.output.data == null) {
      throw new Error("Could not parse AI response as valid JSON.")
    }
    const data = response.output.data

    if (!data.length) {

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Open the extract step in the builder and re-select the file source so source and file input match
  2. If source is URL/ATTACHMENT, ensure the file field is the correct type (string URL vs file object)
  3. Re-create the step if the definition was hand-edited and is inconsistent
  4. Validate the automation JSON: source must correspond to the file field's runtime type

Example fix

// before
{ "source": "ATTACHMENT", "file": "https://example.com/a.pdf" } // string with ATTACHMENT source
// after
{ "source": "URL", "file": "https://example.com/a.pdf" }
Defensive patterns

Strategy: validation

Validate before calling

const isUrlSource = inputs.source === DocumentSourceType.URL && typeof file === "string"
const isAttachment = inputs.source === DocumentSourceType.ATTACHMENT && typeof file === "object" && file !== null
if (!isUrlSource && !isAttachment) {
  throw new Error("source and file input types do not match")
}

Type guard

function sourceMatchesInput(inputs: { source: DocumentSourceType }, file: unknown): boolean {
  return (inputs.source === DocumentSourceType.URL && typeof file === "string") ||
    (inputs.source === DocumentSourceType.ATTACHMENT && typeof file === "object" && file !== null)
}

Prevention

When it happens

Trigger: inputs.source is set to a value inconsistent with the file input: e.g. source=ATTACHMENT while file is a string URL, or an unrecognized source value whose branch falls into the else, at automation execution time.

Common situations: Hand-edited or exported/imported automation definitions where source and file fields were changed independently; API-triggered automations passing mismatched payloads; builder version differences altering the step schema.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/cc1b844732e9dc6f. Report an issue: GitHub.