String
Record string values with pattern validation.
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.
| Property | Type | Required | Description |
|---|---|---|---|
key | string | No | Unique identifier for the measurement within the phase |
name | string | Yes | Display name (1-100 characters) |
unit | string | No | Measurement unit (e.g., "sn", "ver", max 50 characters) |
description | string | No | Detailed 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:
| Property | Type | Required | Description |
|---|---|---|---|
operator | string | Yes | Comparison operator |
expected_value | string or array | Yes | Expected value(s) or regex pattern |
You can use the following operators for string measurements:
| Operator | Expected Value | Description | Example |
|---|---|---|---|
== | String | Value must equal expected | expected_value: "PASS" |
!= | String | Value must not equal expected | expected_value: "ERROR" |
in | Array of strings | Value must be in the array | expected_value: ["v1.0.0", "v1.0.1"] |
not in | Array of strings | Value must not be in the array | expected_value: ["FAIL", "ERROR"] |
matches | Regex pattern | Value must match regex pattern | expected_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:
phases:
- name: Error Message Check
python:
module: check_errors
measurements:
- name: Error Message
description: Error message from device diagnostic
validators:
- operator: matches
expected_value: "^(OK|PASS|SUCCESS)$"def check_errors(run, 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:
phases:
- name: Status Check
python:
module: 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(run, 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?