CONSTRAINTS to enforce business rules on data the agent holds. Use GUARDRAILS to inspect the text that enters and leaves the agent. Use a field type or validate: rule to check the format of one collected value.
Concept
Four ABL features can all stop an agent from doing something. They check different things at different moments.
Two differences matter most.
Condition direction. A constraint states what must be true.
REQUIRE refund_amount <= 500 fails when the amount is 900. A guardrail check states what is wrong. A guardrail fails when its check is true. Use RESTRICT in a constraint to write a prohibited state instead: RESTRICT refund_amount > 500 has the same effect as the REQUIRE above.
What happens on a violation. A constraint steers the conversation. A guardrail protects the content.
Minimal working example
A refund agent combines all three. The order number must match a pattern. A refund above 500 must go to a person and must never reach the refund tool. Messages that try to override the agent’s instructions are blocked, and replies that contain a card number are blocked.agents/refund-assistant.agent.abl
order_numberandrefund_amountareGATHERfields. The customer supplies both.inputandoutputare the customer message and the agent reply. The runtime binds them for guardrail checks.issue_refundis a project-local tool. Replace it with your real tool and bind it in your project.
- The order number rule rejects “ab12” before the value is stored.
- The constraint stops the refund tool call when the amount is over 500, and escalates.
- The input guardrail stops an injection attempt before the model reads it.
- The output guardrail stops a card number from reaching the customer.
How it works
Constraints
- Every constraint is checked every turn. Named phases such as
pre_refund:are labels only. The compiler warnsW823. - A constraint on a field that has no value yet is skipped. The compiler adds the “is set” guard for you. A
BEFORE calling <tool>rule is the exception: it is decided at the tool call. BEFORE calling <tool>ties a constraint to one tool call. The runtime decides it at that call and blocks the call when the condition is false.BEFORE returning resultsties it to the reply.- Any other
BEFOREtext has no effect. The compiler warnsW824. - A constraint with
WHEN:applies only while that condition is true. WARNrecords a warning and lets the turn continue.REQUIRE,LIMIT, andRESTRICTblock.- A
BEFORErule that cannot be evaluated counts as failed.
Guardrails
- A guardrail has a
kind:input,output,both,tool_input,tool_output, orhandoff. The default isoutput. The default action iswarn. - The guardrail type follows the fields you set:
- Local guardrails run in parallel. Within a tier,
priorityorders the checks and breaks ties between violations. A lower number comes first. The default is 100. reaskmakes the model write its reply again. The limit is 1 to 5 tries, default 2. Each try costs another model call.reask_exhausted_messageis what the customer sees when the tries run out.reaskworks on output guardrails only.fixandfilterare not allowed onhandoffguardrails. The compiler rejects these combinations.- Use the kind’s own variable in a
check:inputin an input guardrail,outputin an output guardrail. A check that reads another kind’s variable never matches. The compiler warns.
When the check itself fails
Set the fail mode deliberately for any guardrail that protects against harm.
Common variations
Choose the tier for each risk
Use a localcheck for patterns you can write down. Use llm_check for judgments a pattern cannot make, such as tone. This is a section snippet.
fix needs a fix_strategy. Without one, it blocks and the compiler warns.
State the prohibited condition
RESTRICT reads naturally for a ban. WHEN limits when it applies. This is a section snippet.
HANDOFF agent_name in ON_FAIL needs that agent in the same project. The compiler reports INVALID_HANDOFF_TARGET when it does not exist.
Decision table
When two features fit, prefer the one that acts earliest and costs least. A type check is cheaper than a constraint. A local guardrail is cheaper than a model or LLM guardrail.
Verification
Test each rule with one input that breaks it and one that passes. Use a test session and read the trace.
Also check:
- A
guardrail_pipeline_completeevent ends each guardrail run. Aguardrail_pipeline_errorevent means a check could not run. - A
constraint_guard_skippedevent means a constraint was skipped because a field has no value yet.
Production readiness checklist
- Every business rule that must hold is a constraint, not only prose in
GOALorPERSONA. - Every constraint that guards a tool call uses
BEFORE calling <tool>with the exact tool name. - Every
ON_FAILtarget exists: the escalation queue, the handoff agent, the flow step. - Each guardrail has a
messageor reask text in every language you support. - Your project policy sets
failModeon purpose for guardrails that protect against harm. - Model-tier and LLM-tier guardrails have a latency and cost budget. A
reaskguardrail can add up to 5 model calls to one reply. - You tested one passing and one failing input for every rule, including an unset field.