Skip to main content
Back to how-to guides Use 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
Variable sources:
  • order_number and refund_amount are GATHER fields. The customer supplies both.
  • input and output are the customer message and the agent reply. The runtime binds them for guardrail checks.
  • issue_refund is a project-local tool. Replace it with your real tool and bind it in your project.
Each feature does its own job:
  • 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 warns W823.
  • 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 results ties it to the reply.
  • Any other BEFORE text has no effect. The compiler warns W824.
  • A constraint with WHEN: applies only while that condition is true.
  • WARN records a warning and lets the turn continue. REQUIRE, LIMIT, and RESTRICT block.
  • A BEFORE rule that cannot be evaluated counts as failed.

Guardrails

  • A guardrail has a kind: input, output, both, tool_input, tool_output, or handoff. The default is output. The default action is warn.
  • The guardrail type follows the fields you set:
  • Local guardrails run in parallel. Within a tier, priority orders the checks and breaks ties between violations. A lower number comes first. The default is 100.
  • reask makes the model write its reply again. The limit is 1 to 5 tries, default 2. Each try costs another model call. reask_exhausted_message is what the customer sees when the tries run out.
  • reask works on output guardrails only. fix and filter are not allowed on handoff guardrails. The compiler rejects these combinations.
  • Use the kind’s own variable in a check: input in an input guardrail, output in 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 local check 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_complete event ends each guardrail run. A guardrail_pipeline_error event means a check could not run.
  • A constraint_guard_skipped event 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 GOAL or PERSONA.
  • Every constraint that guards a tool call uses BEFORE calling <tool> with the exact tool name.
  • Every ON_FAIL target exists: the escalation queue, the handoff agent, the flow step.
  • Each guardrail has a message or reask text in every language you support.
  • Your project policy sets failMode on purpose for guardrails that protect against harm.
  • Model-tier and LLM-tier guardrails have a latency and cost budget. A reask guardrail 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.

Common mistakes

Troubleshooting