String

Last updated on June 16, 2026

MAC Address
AC:19:4F
xmatches/^[A-F0-9:]+$/
PASS
Error Message
Invalid config
xmatches/^OK$/
FAIL
Batch Number
LOT-123
x==LOT-123
PASS
String Measurement: Error Message
  Value: "Invalid config"
  Validator: matches ^OK$
  Outcome: FAIL ("Invalid config" does not match ^OK$)

You can create a string measurement with measurements:

measurements:
  - name: Error Message
    validators: 
      - operator: matches
        expected_value: "^OK$"

You can set the measurement value in your Python phase:

def check_status(run, measurements, device):
    message = device.get_error_message()
    measurements.error_message = message 

Definition

You can configure the measurement name and metadata.

PropertyTypeRequiredDescription
keystringNoUnique identifier for the measurement within the phase
namestringYesDisplay name (1-100 characters)
unitstringNoMeasurement unit (e.g., "sn", "ver", max 50 characters)
descriptionstringNoDetailed description (max 50,000 characters)

TofuPilot auto-generates the key from name (snake_case) if not specified, and uses it for Python access (e.g., measurements.serial_number). The unit and description display in the web interface and reports.

Validators

You can add one or several validators to your measurement using the following properties:

PropertyTypeRequiredDescription
operatorstringYesComparison operator
expected_valuestring or arrayYesExpected value(s) or regex pattern

You can use the following operators for string measurements:

OperatorExpected ValueDescriptionExample
==StringValue must equal expectedexpected_value: "PASS"
!=StringValue must not equal expectedexpected_value: "ERROR"
inArray of stringsValue must be in the arrayexpected_value: ["v1.0.0", "v1.0.1"]
not inArray of stringsValue must not be in the arrayexpected_value: ["FAIL", "ERROR"]
matchesRegex patternValue must match regex patternexpected_value: "^SN[0-9]{8}$"

TofuPilot evaluates validators and sets the outcome to PASS if met, FAIL if not, or UNSET if no value provided.

Examples

Pattern Matching with Regex

We will validate error messages match expected pattern:

plugs:
  - key: device
    name: Device
    python: plugs.device:Device

main:
  - name: Error Message Check
    python: phases.check_errors
    measurements:
      - name: Error Message
        description: Error message from device diagnostic
        validators:
          - operator: matches
            expected_value: "^(OK|PASS|SUCCESS)$"
def check_errors(log, measurements, device):
    log.info("Checking device error message")

    message = device.get_error_message()
    measurements.error_message = message

    if not message in ["OK", "PASS", "SUCCESS"]:
        log.warning(f"Unexpected message: {message}")

Status Code Validation

We will validate device status codes with array matching:

plugs:
  - key: device
    name: Device
    python: plugs.device:Device

main:
  - name: Status Check
    python: phases.check_status
    measurements:
      - name: Device Status
        description: Device operational status code
        validators:
          - operator: in
            expected_value: ["OK", "READY", "IDLE"]
          - operator: not in
            expected_value: ["ERROR", "FAULT", "FAILED"]
def check_status(log, measurements, device):
    log.info("Reading device status")

    status = device.get_status()
    measurements.device_status = status

    if status in ["ERROR", "FAULT", "FAILED"]:
        log.error(f"Device in error state: {status}")

How is this guide?

On this page