Skip to main content
Guardrails are checkpoint functions that keep agent behavior safe and predictable. Use them to validate incoming messages before execution and validate responses before delivery.

Choose the Right Guardrail

TypeRuns WhenOn FailurePage
Input GuardrailsBefore the agent processes inputReturn guidance (non-strict) or raise InputGuardrailTripwireTriggered (strict)Input Guardrails
Output GuardrailsAfter the agent drafts output, before deliveryRetry up to validation_attempts, then raise OutputGuardrailTripwireTriggeredOutput Guardrails

Runnable GitHub Examples

Best Practices

  • Keep each guardrail focused on one responsibility.
  • Write clear output_info messages so the model knows how to recover.
  • Use non-strict mode for guidance and strict mode for hard requirements.
  • For tool argument validation (field/model validators), use Input Validation.