Concept
A pattern finds a value by its shape. It runs on the raw message text and needs no model call. You can attach a pattern in three places.
Built-in patterns exist for
email and phone fields. A phone value is also normalized to E.164 format.
Extraction and validation are different jobs. Use EXTRACTION_PATTERN to find a value in free text. Use VALIDATE to reject a value of the wrong format. A TYPE: pattern entity extracts. It does not enforce the pattern when the value is stored. To enforce a format, add VALIDATE on the field.
Minimal working example
A ticket lookup agent finds a ticket ID by its shape, finds an order number after the word “order”, and accepts an optional phone number.- All three variables are
GATHERfields that the customer supplies. EXTRACTION_GROUP: 1returns only the six digits, not the word “order”.
How it works
How a pattern runs:- The runtime searches the whole message. A match can appear anywhere in the text.
- Matching is case-sensitive. Add
(?i)at the start for case-insensitive matching. - Every match becomes a candidate value.
EXTRACTION_GROUPis the capture group to return. The default is 0, the whole match. A group number that does not exist falls back to the whole match, and the compiler does not warn.- A field pattern overrides an entity pattern.
- The pattern step runs only for entities and fields that have a pattern, and for
emailandphonetypes. - When nothing matches, the field stays empty. A model-based step can still fill it, unless the strategy is
pattern. The step asks again if the field is still empty.
^ and $ for extraction. An anchored pattern matches nothing inside a full sentence. Use anchors in VALIDATE, where the whole value is checked.
Write one backslash
The runtime keeps the text of a pattern exactly as you write it. It does not unescape.
A double backslash compiles with no error and never matches. This applies to
PATTERN, EXTRACTION_PATTERN, and VALIDATE.
What the compiler allows
The platform uses a safe regular expression engine.- The pattern is limited to 500 characters.
- Lookahead, lookbehind, and back-references such as
\1are compile errors. The whole agent fails to compile. - An unclosed bracket is a compile error.
(?i),(?:...), named groups,\b,\d, and anchors work.- A group that contains
+or*and is then repeated is rejected, even when harmless. For example,(\d+)?and(\d+)+fail. Rewrite the group, or use a bounded quantifier such as(\d{3}[-. ]?){2}\d{4}.
Common variations
Pattern on a field with no entity
UseEXTRACTION_PATTERN on a field when only one field needs it. The ticket example does this for order_number.
Built-in email and phone
SetTYPE: email or TYPE: phone. The built-in extractor finds the value. For a phone number, the default country is the US, or the country from the conversation locale. Set STRATEGY: pattern to keep extraction deterministic and skip the model.
Pattern plus a format check
AddVALIDATE, RETRY_PROMPT, and MAX_RETRIES after extraction, as the order number does. The validation runs on the stored value. A regular expression VALIDATE rejects every value of type number, integer, currency, or boolean, so collect an ID as string.
Choose the extraction engine
STRATEGY sets the engine for one field. The values are auto, ml, llm, hybrid, and pattern. hybrid is another name for auto. The order of precedence is the field, then the step block, then the project extraction mode. A pattern field with no EXTRACTION_PATTERN extracts only built-in email and phone values.
Verification
- Run the validator. Expect no errors and no warnings.
- Say “ticket TKT-123456 for order 654321”. Expect
ticketto beTKT-123456andorder_numberto be654321. - Say “my ticket is tkt-123456”. Expect no match, because the pattern is case-sensitive.
- Say “order 12345”. Expect the extraction to find five digits, fail the six-digit rule, and ask again with the retry prompt.
- Say “call me on 415 555 0100”. Expect
callback_phoneas+14155550100. - In the trace, open the
patternstage result. It lists the matches, or showsskippedwhen no pattern applies.
Production readiness checklist
- Every pattern uses single backslashes.
- Every pattern avoids lookaround, back-references, and repeated groups with
+or*. - Extraction patterns are not anchored. Validation patterns are anchored.
- Each ID field has a
VALIDATErule when the format must be exact. - Tests cover lowercase input, extra text around the value, two matches in one message, and no match.
- Phone and email fields have a country or locale test.
Common mistakes
Troubleshooting
Related articles: