validate: "<regex>" to a text GATHER field to accept only values that match. Add extraction_pattern to pull the value out of a longer sentence first.
Concept
ABL has two regex settings. They do different jobs.
Use
validate: for formats that a field type cannot express, such as an order number or a ZIP code. Use extraction_pattern when customers wrap the value in words, such as “my order is AB123456, please check”.
Three rules decide whether a pattern works:
- A
validate:pattern matches anywhere in the value.[A-Z]{2}[0-9]{6}accepts “xx AB123456 yy”. Anchor with^and$to require the whole value. - Patterns run on a safe engine. Lookahead
(?=, lookbehind, and backreferences such as\1are not supported. Nested quantifiers such as(a+)+are rejected. - Patterns test text only. On an
integer,number, orbooleanfield, the stored value is not text, so the rule always fails. Put the rule on astringfield.
Minimal working example
An order-status agent accepts an order number of two capital letters and six digits, and a US ZIP code.agents/order-status-intake.agent.abl
order_numberandzip_codeareGATHERfields. The customer supplies both.COMPLETEreads both in its condition and reply.- This agent stops at a confirmation message. A real agent passes the two values to a lookup tool that you define in your project.
\d. ABL does not unescape the text between the quotes.
How it works
- The customer replies. The runtime extracts a value for the field.
- The runtime applies the field type. A
stringaccepts any text. - The runtime tests the value against
validate:. - A match stores the value. No match drops the value, and the field stays missing.
- The agent asks again.
retry_promptis the re-ask text for the field.max_retriescounts failures for that field and records avalidation_max_retriestrace event when the limit is reached.
Matching is case-sensitive. Add
(?i) at the start for a case-insensitive match. A value with a trailing newline does not match a pattern that ends in $.
validation_process: REGEX is the default for a validate: rule. You can omit it. validation_process: LLM replaces the regex with a model judgment and is not covered here.
Common variations
Pull the value out of a sentence
Setextraction_pattern and strategy: pattern. The runtime then finds the value with your regex alone, with no model call. Keep validate: as the final gate.
agents/ticket-lookup.agent.abl
ticket_id with TKT-123456. “tkt-123456” does not match, because the extraction pattern is case-sensitive.
strategy: accepts auto, ml, llm, hybrid, and pattern. Any other word is compile error E170. hybrid is an old name for auto.
Capture one part of a match
Wrap the part you want in parentheses and setextraction_group to its number. Group 0 is the whole match and is the default. A group number the pattern does not have falls back to the whole match.
This is a section snippet.
TKT-123456. A bare “TKT-123456” does not match, because this pattern requires the words before it.
Share a pattern across fields with ENTITIES
Declare the pattern once inENTITIES and point fields at it with entity_ref. The entity PATTERN is used as the field’s extraction pattern. It does not reject values by itself, so keep validate: on the field.
This is a section snippet.
Hide the value
Setsensitive: true on a field that holds personal data. Rejection messages and traces then leave out the value. See Collect sensitive or PII fields safely.
Verification
Send these messages in a test session, then open the trace.
Check in the trace:
- The extracted candidate for the field, with the stage
pattern. - The validation error for a rejected value.
- The stored value in the session data.
Production readiness checklist
- Every
validate:pattern starts with^and ends with$, unless a partial match is intended. - Rules sit on
stringfields only. - Each pattern was tested with a good value, a wrong-case value, a too-long value, and a value with extra words.
- Every field with
validate:also has aretry_promptthat shows an example of a good value. - You chose what happens after
max_retries: escalation, a handoff, or a graceful end. - Patterns with
extraction_patternandvalidate:agree on case. - Fields with personal data set
sensitive: true. - Downstream tools accept the format you validate.