Validation functions

assert_not_blurry

assert_not_blurry(input_val)

Determines whether the input image is not blurry.
In order to use this function, make sure to enable this flag in the Process Files step by setting "detect_blurry_files" to true in the OCR Config box.

Args:
    input_val (dict): Any IBOCR Record dictionary.

Returns:
    True if validation is successful. Otherwise, throws an Exception and report blur factor.

assert_not_empty

assert_not_empty(input_val)

Determines whether the input value exists.
If the input is a string, will validate if the string has a length > 0.

Args:
    input_val (Any): Any input.

Returns:
    True if validation is successful. Otherwise, throws an Exception.

Examples:
    assert_not_empty('') -> False

assert_true

assert_true(input_val)

Determines whether the input value is true.

Args:
    input_val (Any): Any input.

Returns:
    True if validation is successful. Otherwise, throws an Exception.

Examples:
    assert_true(10 == 15) -> False

cast

cast(val, casted_type)

Casts a value to a specific type.
Casting is needed for validation, as every field must return a specific
type to be re-run. For example, IF() can return any type, therefore,
one must cast the output to the desired type.

Args:
    val (Any): Any input.
    casted_type (str): An allowed type for casting.

Returns:
    The value passed into it, but adjusts the registered return type
    used for validation.

Examples:
    cast(INPUT_COL, 'string') -> INPUT_COL

validate

validate(validation_formulas)

Provide rules to validate a given field.

Args:
    validation_formulas (list[str]): A list of strings (with quotes). Each string is a formula containing a validator.

Returns:
    A dictionary represented as a JSON string. Will have a "status" field, which is set to "OK" if validation was
    successful, else "ERROR". If status "ERROR", it will have a "msgs" field too, a list of each error message string.

Examples:
    validate(['assert_not_empty(INPUT_COL)']) -> '{"status":"OK"}'