Many nf-core workflows use the nf-validation package to validate input parameters. To prevent workflows from failing at runtime due to invalid parameter values, the Latch SDK provides a way to use regex to validate inputs before the workflow is launched.

Developers can easily add parameter validation to their workflows adding the rules field to the NextflowParameter that requires validation. For example:

from latch.types.metadata import NextflowParameter, LatchRule
from latch.types.directory import LatchFile

from pathlib import Path

generated_parameters = {
  'fastq': NextflowParameter(
    type=LatchFile,
    rules=[
      LatchRule(
        # only allow file paths that do not contain spaces
        regex=r"^[^\s]+$",
        # error message to display if the regex fails
        message="File path cannot contain spaces."
      )
    ],
  )
}

In the example above, the fastq parameter is validated to ensure that the file path does not contain spaces. If the regex fails, the error message “File path cannot contain spaces.” is displayed to the user.