Guardrails are checkpoint functions that keep agent behavior safe and predictable. Use them to validate incoming messages before execution and validate responses before delivery.Documentation Index
Fetch the complete documentation index at: https://agency-swarm.ai/llms.txt
Use this file to discover all available pages before exploring further.
Choose the Right Guardrail
| Type | Runs When | On Failure | Page |
|---|---|---|---|
| Input Guardrails | Before the agent processes input | Return guidance (non-strict) or raise InputGuardrailTripwireTriggered (strict) | Input Guardrails |
| Output Guardrails | After the agent drafts output, before delivery | Retry up to validation_attempts, then raise OutputGuardrailTripwireTriggered | Output Guardrails |
Runnable GitHub Examples
- Input guardrails example:
examples/guardrails_input.py - Output guardrails example:
examples/guardrails_output.py
Best Practices
- Keep each guardrail focused on one responsibility.
- Write clear
output_infomessages 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.