> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cradl.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Logical expression

> Check that numbers across fields add up.

The **Logical expression** validator checks a numeric relationship between fields. It is how you catch documents where each field looks fine on its own but the numbers do not agree — a total that does not match its line items, a discount larger than the price.

```
net_amount + vat_amount  =  total_amount
total_amount             >  0
```

## Options

You build two expressions and choose how to compare them.

| Option | What it does |
| - | - |
| **Left and right expression** | Each is built from field values, plain numbers, and the `+`, `-`, `*` and `/` operators. |
| **Operator** | How the two sides are compared: `=`, `<`, `>`, `≤` or `≥`. |

## How it behaves

| Situation | Result |
| - | - |
| The comparison holds | Passes |
| The comparison does not hold | Flagged — `Logical expression not satisfied`, or your own message |
| A field in the expression has no value | Flagged — the check cannot be evaluated |
| A field in the expression is not a number | Flagged — `Got non-numeric value in logical expression` |

Because a missing value makes the check impossible to evaluate, pair this with [Cannot be empty](/core-concepts/ai-model/validators) on the fields involved if they are required.

<Note>
  The comparison is numeric. Fields used in the expression should have a [Numeric formatter](/core-concepts/ai-model/numeric-formatter) so that values like `1 234,56` are turned into numbers before the check runs. Dates and text cannot be compared this way.
</Note>

<Tip>
  Totals rarely match to the last decimal once rounding is involved. If a strict `=` flags documents that are actually correct, compare against a small tolerance instead — for example check that the difference is `≤ 0.01`.
</Tip>
