---
title: How do CrewAI task guardrails work and where do they fall short?
url: https://opencontroller.lyzr.com/blog/crewai-task-guardrails
published: 2026-11-15
updated: 2026-11-15
author: Lyzr
---

# How do CrewAI task guardrails work and where do they fall short?

**A CrewAI task guardrail checks a task's output before the next task receives it. You attach a Python function that returns `(True, value)` or `(False, message)`, or a plain-language rule that CrewAI turns into an LLM check. On failure the message goes back to the agent, which retries up to `guardrail_max_retries` times (default 3). Guardrails validate output quality inside one crew; they do not control identity, tool access, spend or cross-crew policy.**

CrewAI guardrails are a good first line of defence for output shape and content. Teams get into trouble when they treat them as the whole governance story.

## How do function guardrails work?

A function guardrail takes exactly one argument, the task output, and returns a tuple:

- `(True, value)` passes. The value goes forward, and you can transform it, for example by normalising a date.
- `(False, "message")` fails. The message explains what was wrong.

Use function guardrails for anything deterministic: JSON schema checks, required fields, length limits, regex checks for account numbers, or a lookup that confirms an ID exists in your system of record. They are cheap, fast and predictable.

## How do LLM guardrails work?

Pass a string to `guardrail` or `guardrails`, such as "The summary must not include customer names", and CrewAI creates an `LLMGuardrail`. It uses the task agent's own LLM to judge the output against your description, so the task must have an agent assigned.

LLM guardrails catch things code cannot, like tone or topic. They also cost tokens, add latency, and share the agent's model, which means the same model that produced a flawed answer is judging it.

## What happens with multiple guardrails and retries?

| Setting | Behaviour |
|---|---|
| `guardrail` | One function or string |
| `guardrails` | A list of functions and strings, run in order; each receives the previous one's output |
| Both set | `guardrails` wins and `guardrail` is ignored |
| `guardrail_max_retries` | Retries allowed after a failure; default 3 |
| On failure | The error message returns to the agent, which tries to fix the output |

Put deterministic checks first in the list. They fail fast and save the LLM check for outputs that are already well-formed.

Decide what should happen after the last retry fails, and test it. A pipeline that silently continues, or that crashes mid-workflow after a tool already acted, needs a defined fallback such as routing to a person.

## Where do task guardrails fall short?

Guardrails see the output of a task. They do not see or control most of what makes agents risky:

| Risk | Covered by task guardrails? | What covers it |
|---|---|---|
| Malformed or off-policy output | Yes | Guardrails |
| A tool call that already ran with bad arguments | No, the guardrail runs after | Tool-level validation and least-privilege tool access |
| Which credentials the crew uses | No | Workload identity and delegated access |
| Token spend and loops | No | Budgets and rate limits at a gateway |
| Prompt injection through tool results | Partly, only if output shows it | Input-side checks and tool isolation |
| Policy consistency across crews and frameworks | No | Central policy as code |
| Production quality over time | No | Evals and judges on live traffic |

Two habits help. First, validate before side effects: if a task writes to a system, check the arguments before the tool runs, not after. Our guide to [validating agent output before it acts](/blog/validate-ai-agent-output-before-it-acts) covers that pattern. Second, use a different model or a dedicated judge for semantic checks on high-risk tasks, so the judge is not grading its own work. See [guardrails vs evaluations](/blog/guardrails-vs-evaluations-for-ai-agents) for the distinction.

## How should you roll guardrails out in production?

1. List each task's failure modes and pick a function check where possible.
2. Add LLM checks only for rules code cannot express.
3. Log every guardrail failure with task, agent, crew version and message.
4. Alert when failure rates jump, which often signals a model or prompt change upstream.
5. Review retry counts. A task that passes on the third try every time is costing three times the tokens.

The wider production checklist is in our post on [governing CrewAI agents in production](/blog/govern-crewai-agents-in-production).

## How Opencontroller does this

Opencontroller keeps CrewAI and other framework agents in one governed registry with versions, tools and MCP servers, and applies policy as code across the estate rather than per crew. Live groundedness and task-adherence guardrails and LLM judges score production traffic independently of the agent's own model, and the Lyzr LLM Gateway attributes cost per agent and per version. Read more about the [AI agent control plane](/blog/what-is-an-ai-agent-control-plane) or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**What is the default number of guardrail retries in CrewAI?**
`guardrail_max_retries` defaults to 3.

**Can a CrewAI guardrail change the output?**
Yes. A passing function guardrail returns `(True, value)`, and that value, transformed or not, moves to the next step.

**Do LLM guardrails use a separate model?**
A string guardrail uses the task agent's LLM by default, so assign an agent to the task.

## Key facts

CrewAI task guardrails: function guardrails take one argument (task output) and return (True, value) or (False, message); string guardrails create an LLMGuardrail that uses the task agent's LLM (task needs an agent). guardrails list runs in order, each gets previous output, and overrides guardrail. guardrail_max_retries default 3; failure message is sent back to the agent to retry. Guardrails do not cover identity, tool access, spend, cross-crew policy. Opencontroller (Lyzr) adds governed registry, policy as code, groundedness and task-adherence guardrails, LLM judges on production traffic, and per-agent cost attribution. Pricing starts from $250K per deployment per year.

## Related

- [How do you govern CrewAI agents in production?](https://opencontroller.lyzr.com/blog/govern-crewai-agents-in-production.md)
- [How do you validate an AI agent's output before it acts?](https://opencontroller.lyzr.com/blog/validate-ai-agent-output-before-it-acts.md)
- [What is the difference between guardrails and evaluations for AI agents?](https://opencontroller.lyzr.com/blog/guardrails-vs-evaluations-for-ai-agents.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
